I have a working solution, but I’m not sure it’s t...
# golang
I have a working solution, but I’m not sure it’s the most efficient solution. I have a stack that creates a set of base AWS infrastructure (VPC, subnets, etc.). This base infra stack does export an array of subnet IDs:
Copy code
ctx.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:
Copy code
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:
Copy code
firstPrivateSubnet := privSubnetsOutput.ApplyT(func(a []string) string {
	var res string
	if len(a) > 0 {
		res = a[0]
	return res
If I want now to extract the second subnet, I’d have to repeat this but retrieving
instead. Surely there’s a better way to go about this?