Skip to content

Commit 775adb2

Browse files
authored
Merge pull request #18010 from justinsb/nlb_npe
fix: avoid panic if subnet ID is nil
2 parents 4ad354e + e1b5769 commit 775adb2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

upup/pkg/fi/cloudup/awstasks/network_load_balancer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,26 @@ func (*NetworkLoadBalancer) CheckChanges(a, e, changes *NetworkLoadBalancer) err
441441
if len(changes.SubnetMappings) > 0 {
442442
expectedSubnets := make(map[string]*string)
443443
for _, s := range e.SubnetMappings {
444+
subnetID := fi.ValueOf(s.Subnet.ID)
445+
if subnetID == "" {
446+
return fmt.Errorf("Subnet ID is required for subnet name=%v", fi.ValueOf(s.Subnet.Name))
447+
}
444448
if s.AllocationID != nil {
445-
expectedSubnets[*s.Subnet.ID] = s.AllocationID
449+
expectedSubnets[subnetID] = s.AllocationID
446450
} else if s.PrivateIPv4Address != nil {
447-
expectedSubnets[*s.Subnet.ID] = s.PrivateIPv4Address
451+
expectedSubnets[subnetID] = s.PrivateIPv4Address
448452
} else {
449-
expectedSubnets[*s.Subnet.ID] = nil
453+
expectedSubnets[subnetID] = nil
450454
}
451455
}
452456

453457
for _, s := range a.SubnetMappings {
454-
eIP, ok := expectedSubnets[*s.Subnet.ID]
458+
subnetID := fi.ValueOf(s.Subnet.ID)
459+
if subnetID == "" {
460+
return fmt.Errorf("Subnet ID is required for subnet name=%v", fi.ValueOf(s.Subnet.Name))
461+
}
462+
463+
eIP, ok := expectedSubnets[subnetID]
455464
if !ok {
456465
return fmt.Errorf("network load balancers do not support detaching subnets")
457466
}

0 commit comments

Comments
 (0)