is there a recommended way to validate/infer the t...
# typescript
b
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
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
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
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
no worries, thanks for your help (yet again :D)
👍 1