Skip to content

Commit e5dedfa

Browse files
committed
fixup! ec2: enable primary IPv6 on ENI for EC2 instances
1 parent 6f37668 commit e5dedfa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,9 @@ func getInstanceCPUOptionsRequest(cpuOptions infrav1.CPUOptions) *types.CpuOptio
13961396
return request
13971397
}
13981398

1399+
// shouldEnablePrimaryIpv6 determines whether to enable a primary IPv6 address for an instance.
1400+
// It returns true if both the VPC has IPv6 enabled and the instance's subnet has an IPv6 CIDR block.
1401+
// This is required when registering instances by ID to IPv6 target groups.
13991402
func (s *Service) shouldEnablePrimaryIpv6(i *infrav1.Instance) (bool, error) {
14001403
var enablePrimaryIpv6 bool
14011404

@@ -1416,6 +1419,13 @@ func (s *Service) shouldEnablePrimaryIpv6(i *infrav1.Instance) (bool, error) {
14161419
if len(sns) == 0 {
14171420
return false, fmt.Errorf("expected subnet %q for instance to exist, but found none", i.SubnetID)
14181421
}
1422+
if len(sns) > 1 {
1423+
subnetIDs := make([]string, len(sns))
1424+
for i, sn := range sns {
1425+
subnetIDs[i] = aws.ToString(sn.SubnetId)
1426+
}
1427+
return false, fmt.Errorf("expected 1 subnet with id %q, but found %v: %v", i.SubnetID, len(sns), subnetIDs)
1428+
}
14191429
for _, set := range sns[0].Ipv6CidrBlockAssociationSet {
14201430
if set.Ipv6CidrBlockState.State == types.SubnetCidrBlockStateCodeAssociated {
14211431
enablePrimaryIpv6 = true

0 commit comments

Comments
 (0)