Hi, is there any documentation on how ProvidersBag...
# general
g
Hi, is there any documentation on how ProvidersBag work? https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/pulumi/#ComponentResourceOptions-providers I am curious how to select an appropriate provider in the child in case I have multiple AWS providers The demo is made with ACM certificates because you typically need 2 of them, one in the region of ALB and the second one in us-east-1 for CloudFront
Copy code
const a = new aws.Provider("a", {
  region: "eu-central-1",
});

const b = new aws.Provider("2", {
  region: "us-east-2",
});


// now inside the component resource 


export class ComponentThing extends pulumi.ComponentResource {
  
  public readonly taskDefinition: awsnative.ecs.TaskDefinition;

  constructor(name: string, args: {}, opts?: pulumi.ComponentResourceOptions) {
    super("myComponent", name, {}, opts);
    const parent = this
   new aws.acm.Certificate("ue1",{parent, provider: parent.getProvider('this should be us-east-1') })

   new aws.acm.Certificate("ec1",{parent, provider: parent.getProvider('this should be eu-central-1') })
}}
Until now I've been explicitly passing providers via
args
but
opts
is IMO the correct way to do it, the question is how to get a proper provider from there?
r
from a development perspective, i would suggest just passing / tracking the references to those provders you created- e.g.
export const a =
and then using them directly, instead of trying to pull them from some internal mechanism. I dont think
parent.getProvder
here does what you expect
Copy code
export const a = new aws.Provider("a", {
  region: "eu-central-1",
});

export const b = new aws.Provider("2", {
  region: "us-east-2",
});


// now inside the component resource 
import {a, b} from "../aws_provders"

export class ComponentThing extends pulumi.ComponentResource {
  
  public readonly taskDefinition: awsnative.ecs.TaskDefinition;

  constructor(name: string, args: {}, opts?: pulumi.ComponentResourceOptions) {
    super("myComponent", name, {}, opts);
    const parent = this
   new aws.acm.Certificate("ue1",{parent, provider: a})
   new aws.acm.Certificate("ec1",{parent, provider: b})
}}
g
Interesting idea, I will think about it. I also verified that
parent.getProvder
sure does what I expected it to do.
r
ok, send me a snippet if you get a chance, i am curious how it works also
g
here it is, you may need to fix some syntax errors if you are going to run it
Copy code
import * as aws from "@pulumi/aws";
import * as awsnative from "@pulumi/aws-native";
import * as pulumi from "@pulumi/pulumi";

const euCentral1 = aws.Region.EUCentral1;

const provider = new aws.Provider(euCentral1, {
  region: euCentral1,
});

export class ComponentThing extends pulumi.ComponentResource {

  public readonly taskDefinition: awsnative.ecs.TaskDefinition;

  constructor(name: string, args: {}, opts?: pulumi.ComponentResourceOptions) {
    super("providerTest", name, {}, opts);

    const parent = this;
    // parent.getProvider("2");
    const role1 = new  aws.iam.Role("role1", {
      assumeRolePolicy: {
        Version: "2012-10-17",
        Statement: [
          {
            Effect: "Allow",
            Principal: { Service: "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>" },
            Action: "sts:AssumeRole",
          },
        ],
      },
    }, { parent });

    const role2 = new  awsnative.iam.Role("role2", {
      assumeRolePolicyDocument: {
        Version: "2012-10-17",
        Statement: [
          {
            Effect: "Allow",
            Principal: { Service: "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>" },
            Action: "sts:AssumeRole",
          },
        ],
      },
    }, { parent });

    const role3 = new  aws.iam.Role("role3", {
      assumeRolePolicy: {
        Version: "2012-10-17",
        Statement: [
          {
            Effect: "Allow",
            Principal: { Service: "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>" },
            Action: "sts:AssumeRole",
          },
        ],
      },
    }, { parent, provider: parent.getProvider("2") })
}
}
const parent = new  aws.iam.Role("parent", {
  assumeRolePolicy: {
    Version: "2012-10-17",
    Statement: [
      {
        Effect: "Allow",
        Principal: { Service: "<http://ecs-tasks.amazonaws.com|ecs-tasks.amazonaws.com>" },
        Action: "sts:AssumeRole",
      },
    ],
  },
}, { provider });

const native = new awsnative.Provider("native-provider", {
  region: aws.getRegionOutput(undefined, { parent }).name as pulumi.Output<awsnative.Region>,
}, { parent });

const provider2 = new aws.Provider("2", {
  region: aws.Region.USEast1,
});

// new ComponentThing("thing", {}, { parent, providers: { aws: provider, "aws-native": native }});
// new ComponentThing("thing", {}, { parent, provider: native });
new ComponentThing("thing", {}, { providers: [native, provider, provider2] });