https://pulumi.com logo
Title
m

miniature-receptionist-24463

03/24/2023, 1:53 PM
Hello Gurus, I am looking to deploy resource in two different account and using providers. This is my code, how can I use multiple providers to create bucket in two different accounts? const devProvider = new aws.Provider("devProvider", { profile: "dev", region: "us-east-1" }); const prodProvider = new aws.Provider("prodProvider", { profile: "prod", region: "us-west-2" }); . const xyzBucket = new aws.s3.Bucket(
xyz-bucket
, { }, { provider: [devProvider, prodProvider], //Error here });
s

stocky-restaurant-98004

03/24/2023, 2:05 PM
Create 2 resources, each with 1 provider, rather than 1 resource with 2 providers.
But more importantly, I think you actually want a dev and prod stack rather than 1 stack with 2 providers.
Something like:
pulumi stack init dev
pulumi config set aws:region us-east-1
pulumi stack init prod
pulumi config set aws:region us-west-2
pulumi stack select dev
# write your program
pulumi up # deploy to dev
pulumi stack select prod
pulumi up # deploy to prod
Also note that Pulumi will auto-name your resources so that you can deploy the same stack into the same account/region.
m

miniature-receptionist-24463

03/24/2023, 2:09 PM
I know creating two resources is one solution but I am looking if there is anyway to create the same resource with two providers.
I am not using the same name (xyz is just for chat).
I know creating two stacks but requirement here is different. First this stack is actually not part of prod/dev. Second I need to replicate the buckets so I want to keep the name almost same.
s

stocky-restaurant-98004

03/24/2023, 2:24 PM
The autonaming will still be human-readable, but will have a hex hash on the end, e.g. "my-bucket-5489ae"
m

miniature-receptionist-24463

03/24/2023, 2:24 PM
Yes, and I am okay with that.
s

stocky-restaurant-98004

03/24/2023, 2:25 PM
And no, you can't create the same resource with 2 providers. That's actually 2 resources. BUT... you're using a real programming language, so you can use a loop!
The provider is part of what uniquely identifies a resource. 2 different providers, e.g. in 2 regions, is 2 actual buckets.
m

miniature-receptionist-24463

03/24/2023, 2:26 PM
Ok so you mean there is no native way like using array or list?
Do you think this can be added a feature requirement?
s

stocky-restaurant-98004

03/24/2023, 2:27 PM
No, because again - that's 2 separate resources.
You could also make a ComponentResource and pass it a provider. (They're analogous to Terraform modules.)
But I would just start with a function or a loop.
m

miniature-receptionist-24463

03/24/2023, 2:28 PM
Ok. Thanks