https://pulumi.com logo
Title
b

brave-lizard-56518

04/09/2022, 9:21 PM
I’ve written a VPC module written in Golang which uses the Pulumi Automation API, that produces its own stack (with all its metadata, like VPC ID, subnet ID, NAT, etc., exported in a pulumi context), that’s also stored into its own state file in AWS S3. I now need to write several other modules that will be on their separate stacks -- all of which will need the VPC stack metadata, so that they can, for example, be deployed in the subnets of the said VPC. Question: how can I make these other modules load/utilize the VPC stack? Is there a specific method to do this, or do I just have to write a function to load the VPC module’s state file?
e

echoing-dinner-19531

04/09/2022, 9:36 PM
stored into its own state file in AWS S3.
Might make things tricky, if your using different S3 buckets for the different stacks as that's currently seen as different backends and that's not currently supported https://github.com/pulumi/pulumi/issues/3395
b

brave-lizard-56518

04/09/2022, 9:39 PM
Also, the idea is that once the VPC module has already been run (and produced the stack), I don’t need to run that anymore unless there’s a change to it. My new modules should just be able to load the VPC stack/metadata when I have to provision, let’s say an EC2, or RDS, for example.
The S3 bucket is common/shared, but each module will have their own stacks inside it, and managed separately.
e

echoing-dinner-19531

04/09/2022, 10:03 PM
StackReferences should work for you then
👍 1
b

brave-lizard-56518

04/09/2022, 10:47 PM
Thanks, @helpful-vegetable-35581!
b

bored-oyster-3147

04/10/2022, 2:48 AM
FYI you need to make sure that you are providing the same directory within that S3 bucket as a backend path. Different directories are treated as separate backends and you won't be able to stack reference across them, even if they reside in the same bucket
b

brave-lizard-56518

04/10/2022, 12:55 PM
I see. I have to change the directory structure, then.
I’m getting the error below right after this code executes:
stackRef, err := pulumi.NewStackReference(ctx, "poc-vpc-vpc1-dev-iad", nil)
Diagnostics: pulumi😛ulumi:Stack (ec2_v1_alpha1-poc-ec2-okaytodelete-dev-iad): error: an unhandled error occurred: waiting for RPCs: Invoke(pulumi😛ulumi:getResource, ...): error: rpc error: code = Unknown desc = invocation of pulumi😛ulumi:getResource returned an error: unknown resource urn😛ulumi:poc-vpc-vpc1-dev-iad::vpc_v1_alpha1::aws:ec2/subnet:Subnet::poc-vpc1-dev-iad-pub2-subnet It’s able to locate the other stack that my EC2 stack depends on, but it’s complaining about something.
Can anybody help? I’m somewhat stuck on this approach. I also already searched for this same issue here in the community, but I didn’t find a solution.
b

bored-oyster-3147

04/11/2022, 11:46 PM
Unfortunately I'm not sure what this error is so I was hoping someone else would chime in.
e

echoing-dinner-19531

04/14/2022, 9:33 AM
pulumi:pulumi:getResource
doesn't look like a stack reference, that's from a
pulumi.getResource
call
b

brave-lizard-56518

04/14/2022, 9:18 PM
@helpful-vegetable-35581, can you clarify? I don’t have any getResource call other than pulumi.NewStackReference(ctx, “poc-vpc-vpc1-dev-iad”, nil). My hunch is that it’s from a downstream call. Is there anything I’m doing wrong?
e

echoing-dinner-19531

04/15/2022, 9:43 AM
Is there anything I’m doing wrong? (
Not sure. Just that "invocation of pulumi😛ulumi:getResource returned an error" is from a getResource call, not a registerStackReference call but that URN (urn😛ulumi:poc-vpc-vpc1-dev-iad::vpc_v1_alpha1::aws:ec2/subnet:Subnet::poc-vpc1-dev-iad-pub2-subnet) looks like its trying to load a resource from the stack listed in the stack reference, but getResource doesn't work like that it can only return resources in the current stack. I'd try and see where that stackreference gets passed to, and see if that code is trying to make a getResource call.
b

brave-lizard-56518

04/15/2022, 12:59 PM
Hi, @helpful-vegetable-35581, I upgraded my Pulumi version from 3.21 to 3.29 and the error I reported has gone away.
🙌 1