ancient-nightfall-5476405/19/2022, 8:14 AM
But when I run the code, the result was error like this
stack infra index.ts .... export const ruleSgId = secgroup.id; export const subnetA = subneta.id; stack dev index.ts ... const stackRef = new pulumi.StackReference("blabla/blabla/infra"); const secg = stackRef.getOutput("ruleSgId"); const subnet = stackRef.getOutput("subnetA"); subnetId: subnet, vpcSecurityGroupIds: [ secg, ], ...
https://www.pulumi.com/learn/building-with-pulumi/stack-references/ Thank you.
error: Running program '/Users/mhw/WS/repos/pulumi' failed with an unhandled exception: TypeError: Cannot read properties of undefined (reading 'id')
victorious-church-5739705/19/2022, 10:10 AM
on the output
export const ruleSgId = secgroup.id.apply((id) => id);
ancient-nightfall-5476405/19/2022, 1:54 PM
in the output, but the error still same.
clever-sunset-7658505/19/2022, 2:37 PM
stack is having a problem exporting the output due to
being undefined. It is not clear which one is the issue without seeing more code.
ancient-nightfall-5476405/19/2022, 3:55 PM
clever-sunset-7658505/19/2022, 4:14 PM
won't work because you have the variable in that file guarded by an if-condition that would only be true when this stack is
. When you are running as the
stack it will be
. So the issue doesn't seem to be because of stack references. It's an issue with line 7 in your
file at the root of your repo. To make it work you could change it to add an if-condition in
too to see what the current stack is. Structuring your app the way you have it now is confusing to be honest. Is there a reason you do not want to have the infra stack as its own Pulumi project? The code is likely to get more complicated with more conditional branches all over the place the way it is right now. Have a look at the
repo for comparison of how to have multiple Pulumi projects within the same folder.
ancient-nightfall-5476405/20/2022, 1:39 AM
clever-sunset-7658505/20/2022, 2:33 AM
only runs when your stack name is
. So when you run the same code for your
stack, the export in that file is never assigned a value even though the vpc does get created in the
stack. There is a way to get it to work but honestly I think you'll find it more confusing to work with it over time.
ancient-nightfall-5476405/20/2022, 2:51 AM
clever-sunset-7658505/20/2022, 2:52 AM