sparse-intern-71089
03/04/2021, 5:56 PMicy-london-58403
03/04/2021, 5:58 PMbillowy-army-68599
apply
because networkfirewall.FirewallFirewallStatusArrayOutput
isn't actually known until it's created. I don't have a concrete example of your particular use case, but there's an example of ranging over an ArrayOutput
here:
https://github.com/pulumi/examples/blob/e942d6130cd402d48db56889581ce2db1879803f/kubernetes-go-guestbook/components/serviceDeployment.go#L55-L63icy-london-58403
03/04/2021, 6:14 PMicy-london-58403
03/04/2021, 10:20 PMfunc (vpc *VPC) GetFirewallEndpointIDByZone(ctx *pulumi.Context, zone string) pulumi.StringOutput {
ready := pulumi.All(vpc.NetworkFirewall.FirewallStatuses)
return ready.ApplyT(func(statuses []networkfirewall.FirewallFirewallStatus) string {
found := false
for _, status := range statuses {
for _, syncState := range status.SyncStates {
getZoneResult, err := aws.GetAvailabilityZone(ctx, &aws.GetAvailabilityZoneArgs{
AllAvailabilityZones: nil,
Filters: []aws.GetAvailabilityZoneFilter{},
Name: syncState.AvailabilityZone,
State: nil,
ZoneId: nil,
})
if err != nil {
ctx.Log.Error(fmt.Sprintf("Error: %s", err), nil)
}
if getZoneResult.ZoneId == zone {
found = true
return *syncState.Attachments[0].EndpointId
}
}
}
if !found {
ctx.Log.Error(fmt.Sprintf("Error: Could not find firewall endpoint id in zone %s", zone), nil)
}
return ""
}).(pulumi.StringOutput)
}
Error:
panic: applier must have 1 input parameter assignable from []interface {}
billowy-army-68599
white-balloon-205
All
here? That returns an ArrayOutput
which has an underlying type of []interface{}
which is why applyt expects the argument to be of that type. You could change it to match what the error notes, and then convert. But I have a feeling you just don’t need the All call at all? (And would then pass a more strongly typed value to ApplyT so that you could use the applier you have above).icy-london-58403
03/05/2021, 4:10 PMAll
is just being used out of inexperience and ignoranceicy-london-58403
03/05/2021, 4:22 PMicy-london-58403
03/05/2021, 4:26 PMicy-london-58403
03/05/2021, 4:27 PM// GetFirewallEndpointIDByZone
func (vpc *VPC) GetFirewallEndpointIDByZone(ctx *pulumi.Context, zone string) pulumi.StringOutput {
ready := vpc.NetworkFirewall.FirewallStatuses
return ready.ApplyT(func(statuses []networkfirewall.FirewallFirewallStatus) string {
found := false
for _, status := range statuses {
for _, syncState := range status.SyncStates {
getZoneResult, err := aws.GetAvailabilityZone(ctx, &aws.GetAvailabilityZoneArgs{
AllAvailabilityZones: nil,
Filters: []aws.GetAvailabilityZoneFilter{},
Name: syncState.AvailabilityZone,
State: nil,
ZoneId: nil,
})
if err != nil {
ctx.Log.Error(fmt.Sprintf("Error: %s", err), nil)
}
if getZoneResult.ZoneId == zone {
found = true
return *syncState.Attachments[0].EndpointId
}
}
}
if !found {
ctx.Log.Error(fmt.Sprintf("Error: Could not find firewall endpoint id in zone %s", zone), nil)
}
return ""
}).(pulumi.StringOutput)
}
icy-london-58403
03/05/2021, 4:27 PMicy-london-58403
03/05/2021, 4:31 PMicy-london-58403
03/05/2021, 4:31 PMwhite-balloon-205