Skip to content

Commit 36585e2

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 3e9cf47 commit 36585e2

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
@@ -581,14 +581,21 @@ func (s *Service) runInstance(role string, i *infrav1.Instance) (*infrav1.Instan
581581

582582
input.NetworkInterfaces = netInterfaces
583583
} else {
584-
input.NetworkInterfaces = []types.InstanceNetworkInterfaceSpecification{
585-
{
586-
DeviceIndex: aws.Int32(0),
587-
SubnetId: aws.String(i.SubnetID),
588-
Groups: i.SecurityGroupIDs,
589-
AssociatePublicIpAddress: i.PublicIPOnLaunch,
590-
},
584+
netInterface := types.InstanceNetworkInterfaceSpecification{
585+
DeviceIndex: aws.Int32(0),
586+
SubnetId: aws.String(i.SubnetID),
587+
Groups: i.SecurityGroupIDs,
588+
AssociatePublicIpAddress: i.PublicIPOnLaunch,
591589
}
590+
591+
// When registering targets by instance ID for an IPv6 target group,
592+
// the targets must have an assigned primary IPv6 address.
593+
if s.scope.VPC().IsIPv6Enabled() {
594+
netInterface.Ipv6AddressCount = aws.Int32(1)
595+
netInterface.PrimaryIpv6 = aws.Bool(true)
596+
}
597+
598+
input.NetworkInterfaces = []types.InstanceNetworkInterfaceSpecification{netInterface}
592599
}
593600

594601
if i.NetworkInterfaceType != "" {

0 commit comments

Comments
 (0)