Skip to content

Commit bcda5bf

Browse files
committed
fixup! ec2: enable primary IPv6 on ENI for EC2 instances
1 parent 061134a commit bcda5bf

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
@@ -1325,6 +1325,9 @@ func getInstanceCPUOptionsRequest(cpuOptions infrav1.CPUOptions) *types.CpuOptio
13251325
return request
13261326
}
13271327

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

@@ -1345,6 +1348,13 @@ func (s *Service) shouldEnablePrimaryIpv6(i *infrav1.Instance) (bool, error) {
13451348
if len(sns) == 0 {
13461349
return false, fmt.Errorf("expected subnet %q for instance to exist, but found none", i.SubnetID)
13471350
}
1351+
if len(sns) > 1 {
1352+
subnetIDs := make([]string, len(sns))
1353+
for i, sn := range sns {
1354+
subnetIDs[i] = aws.ToString(sn.SubnetId)
1355+
}
1356+
return false, fmt.Errorf("expected 1 subnet with id %q, but found %v: %v", i.SubnetID, len(sns), subnetIDs)
1357+
}
13481358
for _, set := range sns[0].Ipv6CidrBlockAssociationSet {
13491359
if set.Ipv6CidrBlockState.State == types.SubnetCidrBlockStateCodeAssociated {
13501360
enablePrimaryIpv6 = true

0 commit comments

Comments
 (0)