salmon-account-74572
09/01/2022, 8:43 PMctx.Export("privSubnetIds", pulumi.StringArray(privSubnetIds))
I have a second stack in which I need to reference these subnet IDs to launch EC2 instances. I have a StackReference to the base infrastructure stack, but the only way I’ve been able to reference the private subnet IDs has been this incantation:
privSubnetsOutput := ref.GetOutput(pulumi.String("privSubnetIds")).ApplyT(func(out interface{}) []string {
var res []string
if out != nil {
for _, v := range out.([]interface{}) {
res = append(res, v.(string))
}
}
return res
})
Followed by extracting the first subnet:
firstPrivateSubnet := privSubnetsOutput.ApplyT(func(a []string) string {
var res string
if len(a) > 0 {
res = a[0]
}
return res
}).(pulumi.StringOutput)
If I want now to extract the second subnet, I’d have to repeat this but retrieving a[1]
instead. Surely there’s a better way to go about this?No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by