If I have an array of AZ names created like this: ...
# golang
s
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
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
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
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
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
What if you wrap it in
pulumi.StringArray(azNames)
s
That seems to work. I swear I thought I'd tried that already, but 🤷🏻‍♂️
Thanks
👍 1