https://pulumi.com logo
#general
Title
# general
b

bulky-area-51023

11/07/2021, 8:10 PM
Hi! I have a question regarding ComponentResource. I referred to this
providers
map, but I’m not still sure whether I can use two regions of AWS in single componentResource. What could be the best practice when we need multiple AWS providers in single ComponentResource?
l

little-cartoon-10569

11/07/2021, 8:18 PM
You would need two AWS providers, and to explicitly use the appropriate one when creating AWS resources.
Since both providers match when creating AWS resources inside your ComponentResource, you need to specify the correct one. You can do this either by removing the "wrong" provider from the
providers
opt, or by passing the "right" one into the
provider
opt.
The
providers
opt only uses specific keys (and I've never seen where those keys are defined), so in theory you could provide both providers via keys that Pulumi doesn't know about, then explicitly update the map based on the resource you're creating.
Copy code
new MyComponentResource(name, args, { providers: { awsEast1: awsProv1, awsWest2: awsProv2 } });
.....
class MyComponentResource {
  constructor(name, args, opts) {
    ...
    new ResourceInEast1(name1, args1, { ...opts, providers: { ...opts.providers, aws: opts.providers.awsEast1 } });
    new ResourceInWest2(name2, args2, { ...opts, providers: { ...opts.providers, aws: opts.providers.awsWest2 } });
(Utterly untested, that's completely a guess...)