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

salmon-account-74572

07/28/2020, 2:31 AM
If I have an array of AZ names created like this:
Copy code
azNames := make([]string, numOfAZs)
for idx := 0; idx < numOfAZs; idx++ {
	azNames[idx] = rawAzInfo.Names[idx]
}
where
rawAzInfo
is the result of the
aws.GetAvailabilityZones
resource, how can I use that array as an input to the AvailabilityZones argument of the
elb.NewLoadBalancer
resource? Alternately, if I have an array of instance IDs, how could I use that array of instance IDs as an input to the Instances argument of the
elb.NewLoadBalancer
resource?
l

lemon-agent-27707

07/28/2020, 3:34 AM
AvailabilityZones
is of type
pulumi.StringArrayInput
so we would need to construct a
pulumi.StringArray
. https://github.com/pulumi/pulumi-aws/blob/master/sdk/go/aws/elb/loadBalancer.go#L264 Should be something like:
Copy code
azNames := make([]pulumi.StringInput, numOfAZs)
for idx := 0; idx < numOfAZs; idx++ {
	azNames[idx] = pulumi.String(rawAzInfo.Names[idx])
}
Instances should be similar. Happy to provide a code snippet if it would help.
s

salmon-account-74572

07/28/2020, 4:30 AM
OK, thanks for that. I've made the change, but I'm not quite sure how to reference it in the ELB configuration. Is this right...?
Copy code
elb, err := elb.NewLoadBalancer(ctx, fmt.Sprintf("elb-%s", baseName), &elb.LoadBalancerArgs{
	AvailabilityZones: pulumi.StringArray{azNames},
	Instances:         pulumi.StringArray{cpNodeIds},
})
l

lemon-agent-27707

07/28/2020, 4:47 AM
I would expect that you should be able to just reference aznames directly
AvailabilityZones: azNames,
given that
pulumi.StringArrayInput
is just a type alias for
[]pulumi.StringInput
s

salmon-account-74572

07/28/2020, 6:05 AM
That was my thought, too, but
gopls
gives me this: "cannot use azNames (variable of type []pulumi.StringInput) as pulumi.StringArrayInput value in struct literal: missing method ElementType"
@lemon-agent-27707 Sorry to be a pest, any thoughts on this error I get trying to reference my
azNames
array directly in the ELB resource constructor? (I adopted your code for creating the
azNames
array.)
l

lemon-agent-27707

07/29/2020, 4:55 PM
What if you wrap it in
pulumi.StringArray(azNames)
s

salmon-account-74572

07/29/2020, 4:56 PM
That seems to work. I swear I thought I'd tried that already, but 🤷🏻‍♂️
Thanks
👍 1
8 Views