Skip to content

Commit 19ff09b

Browse files
committed
ec2: enable primary IPv6 on ENI for EC2 instances
AWS requires that when registering targets by instance ID for an IPv6 target group, the targets must have an assigned primary IPv6 address. Note: The default subnets managed by CAPA are already set up to assign IPv6 addresses to newly created ENIs.
1 parent 83f241a commit 19ff09b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

pkg/cloud/services/ec2/instances.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,21 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
577577

578578
input.NetworkInterfaces = netInterfaces
579579
} else {
580-
input.NetworkInterfaces = []types.InstanceNetworkInterfaceSpecification{
581-
{
582-
DeviceIndex: aws.Int32(0),
583-
SubnetId: aws.String(i.SubnetID),
584-
Groups: i.SecurityGroupIDs,
585-
AssociatePublicIpAddress: i.PublicIPOnLaunch,
586-
},
580+
netInterface := types.InstanceNetworkInterfaceSpecification{
581+
DeviceIndex: aws.Int32(0),
582+
SubnetId: aws.String(i.SubnetID),
583+
Groups: i.SecurityGroupIDs,
584+
AssociatePublicIpAddress: i.PublicIPOnLaunch,
587585
}
586+
587+
// When registering targets by instance ID for an IPv6 target group,
588+
// the targets must have an assigned primary IPv6 address.
589+
if s.scope.VPC().IsIPv6Enabled() {
590+
netInterface.Ipv6AddressCount = aws.Int32(1)
591+
netInterface.PrimaryIpv6 = aws.Bool(true)
592+
}
593+
594+
input.NetworkInterfaces = []types.InstanceNetworkInterfaceSpecification{netInterface}
588595
}
589596

590597
if i.NetworkInterfaceType != "" {

0 commit comments

Comments
 (0)