https://pulumi.com logo
Title
b

billowy-laptop-50664

11/03/2022, 1:49 PM
Hi all I'm stuck on something that seems like it should be simple. I have a multiple ts file program and am creating a provider in one file (aws provider with different region to the default) now how do I get a reference to this provider without actually passing the reference around?
b

billowy-army-68599

11/03/2022, 1:58 PM
can you elaborate on what you mean by passing it around? you’ll need to reference the provider somehow
are you referring to the terraform behaviour of interpolating all files in a directory? Pulumi doesn’t do that
b

billowy-laptop-50664

11/03/2022, 2:00 PM
@billowy-army-68599 Thanks for the prompt reply. So my default region for aws is
eu-west-2
and I needed to create some resources a few months ago in
us-west-2
. So I created a new provider and set the region. Now I need to add some more resources to
us-west-2
. How do I get this provider from the current stack?
I can't just use the local variable because it's in a different file
previously I did
let provider = new aws.Provider(`default-us-west-2`, {
    region: 'us-west-2'
});
So need to get
default-us-west-2
from the stack!?
b

billowy-army-68599

11/03/2022, 2:02 PM
ah, then export the variable
export const provider = new aws.provider
add an import into the place you want to use it
import * from as westprovider from "./providerfile"
And then you can reference it as
westprovider.provider
b

billowy-laptop-50664

11/03/2022, 2:05 PM
is that the only way? I would have thought you could get resources from the stack. Like you can with
aws.secretsmanager.getSecret()
b

billowy-army-68599

11/03/2022, 2:11 PM
that calls the API of AWS, you can’t
get
a provider
having said that, there’s absolute no downside to just creating another provider, you can create as many as you like
b

billowy-laptop-50664

11/03/2022, 2:13 PM
Yeah it will soon get messy though, I think I'll create a Providers class which keeps static references. This will be tidier than creating lots of providers the same with different names. Thank-you for your time