https://pulumi.com logo
Title
b

bright-orange-69401

07/31/2021, 11:17 AM
Hey there, Does someone know how to use the
StackReference.get_provider
function ? I’m trying to get the AWS provider from stack
A
while in stack
B
to do some cross-account provisioning Here’s the doc I found: https://www.pulumi.com/docs/reference/pkg/python/pulumi/#pulumi.Resource.get_provider What is the
module_member
argument supposed to be exactly ?
g

great-sunset-355

08/01/2021, 4:20 PM
how about this from example?
from pulumi import get_stack, ResourceOptions, StackReference
from pulumi_kubernetes import Provider, core

env = get_stack()
infra = StackReference(f"mycompany/infra/{env}")
provider = Provider("k8s", kubeconfig=infra.get_output("kubeConfig"))
service = core.v1.Service(..., ResourceOptions(provider=provider))
l

little-cartoon-10569

08/01/2021, 9:20 PM
You cannot get the provider from one stack into another. You can create a new provider with all the same parameters, if you pass those parameters by Stack Reference.
StackRefererence.getProvider()
gets the provider used to create the stack, not one of the providers that was created within the stack. You cannot use
StackReference.getProvider()
to achieve anything useful (that provider is the default Pulumi provider, which afaik is null).
b

bright-orange-69401

08/02/2021, 1:40 PM
I see ! Shame, it would’ve been helpful to be able to get the default provider this way ;) Thanks for your help !
l

little-cartoon-10569

08/02/2021, 9:00 PM
The default provider is always
null
.
Each default provider. So your default AWS provider is
null
, default TLS provider is
null
, etc.
And if you want to get a specific provider to be used by two stacks, then pass the same creds into both stacks and initialize both providers the same way. This is kind of a "gimme" in a single project with multiple stacks, and pretty easy in multiple projects.
🙏 1
👍 1