https://pulumi.com logo
#golang
Title
m

mammoth-honey-6147

02/01/2021, 4:16 PM
noobie question - How do I print an array of Pulumi types with
ctx.Export
? I've tried looping round:
Copy code
for _, subnet := range subnets {
			ctx.Export("Subnet CIDR", subnet.CidrBlock)
			ctx.Export("Subnet AZ", subnet.AvailabilityZone)
		}
But, predictably, it only prints the last element in the array
l

lemon-agent-27707

02/01/2021, 8:53 PM
You can construct an export arrays (types might need some work):
Copy code
var outputArray []pulumi.StringOutput
for _, subnet := range subnets {
outputArray = append(outputArray, subnet.CidrBlock)
}
ctx.Export("CidrBlocks", outputArray)
👍 2
m

mammoth-honey-6147

02/01/2021, 9:12 PM
Thank you Evan, will give this a shot.
h

hallowed-author-21638

03/09/2021, 4:16 PM
So I'm trying to iterate on this fine example though I'm falling short on
ctx.Export("Ipv4Address", outputArray)
I get a missing method ElementType
So if I do
ctx.Export("Ipv4Address", outputArray[1])
I get a expected outcome but how can I properly iterate through all the elements in the array to have it reflect in Pulumi's output?
l

lemon-agent-27707

03/09/2021, 7:21 PM
can you share the full code sample and the full exception?
h

hallowed-author-21638

03/09/2021, 8:42 PM
Hi Evan. I ended up settling on this. Unsure if this is the best implementation but it got what I was trying to achieve https://github.com/anthr76/infra/commit/6869acbc00ebe4cfd6617020e191eaf9f6fcd839#diff-035da15de753145796f6d5eb2cc[…]c119dfc32266e12b14c46c685bR1-R19
l

lemon-agent-27707

03/09/2021, 9:43 PM
Great!
3 Views