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?