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

breezy-butcher-78604

01/12/2021, 1:17 AM
is there a recommended way to validate/infer the type of a stack output when referring to it from another stack? for example i have a VPC stack that outputs an array of subnet IDs that I grab with a stack reference like so:
Copy code
const stackRef = new pulumi.StackReference("vpc/dev");

const subnetIds = stackRef.requireOutput("subnetIds");
given the above,
subnetIds
will be of type
Output<any>
but I want to be able to loop over the values because I need to create a resource for each subnet. is creating the resources inside an
apply()
the only option? it seems weird not being able to directly access the values since stack outputs should always be known prior to a
pulumi up
or
preview
right?
l

little-cartoon-10569

01/12/2021, 1:22 AM
They won't always been known, since the other stack could be running at the same time. Pulumi has to support this case.
Generally, outputs from StackReferences are used as inputs for other resources, so this problem doesn't occur. Can you split your outputs to be a collection of outputs, instead of an output that is a collection?
That way, each output can be used directly as an input.
My equivalent code exports
privateSubnet1Id
,
isolatedSubnet2Id
, etc.
b

breezy-butcher-78604

01/12/2021, 1:26 AM
They won't always been known, since the other stack could be running at the same time. Pulumi has to support this case
ah ok, that makes sense
Generally, outputs from StackReferences are used as inputs for other resources
yeah thats typically what happens for me as well but in this case I need to do a foreach over both subnet IDs and route table IDs which i guess isn't possible without an
apply()
l

little-cartoon-10569

01/12/2021, 1:27 AM
Yes, if you export a complex output then you're likely to have to handle it either in an apply, or in a custom provider.
Either rework your "source" stack to export simple outputs, or add the complex code in your "destination" stack.
👍 1
b

breezy-butcher-78604

01/12/2021, 1:29 AM
no worries, thanks for your help (yet again :D)
👍 1
3 Views