fpco / terraform-aws-foundation

Establish a solid Foundation on AWS with these modules for Terraform
MIT License
203 stars 99 forks source link

Add optional IPv6 support to the subnets module and vpc module #312

Open mcgirr opened 4 years ago

mcgirr commented 4 years ago

Currently the vpc and subnets modules support IPv4.

This issue proposes adding (optional) IPv6 support to these modules as well.

Brief background

Currently when we launch an instance into a VPC, a primary private IP address from the IPv4 address range of the subnet is assigned to the default network interface (eth0) of the instance.

Likewise subnets have an attribute that can determine whether a network interface created in the subnet automatically receives a public IPv4 address. So when you launch an instance into a subnet that has this attribute enabled, a public IPv4 address is assigned to the primary network interface (eth0) that's created for the instance. When this happens a public IP address is mapped to the primary private IP address through network address translation (NAT).

You can also associate a public IP address with an option from the instance. An instance in a VPC using the associate_public_ip_address option for the aws_instance resource in Terraform will receive a public IPv4 address. And enabling or disabling the public IP addressing feature during instance launch overrides the subnet's public IP addressing attribute mentioned above.

And of course you can associate an Elastic IP address with your instance.

IPv6

IPv6 is slightly different. An instance in a VPC receives an IPv6 address if an IPv6 CIDR block is associated with the VPC and the subnet.

The goal of this issue is to:

  1. Allow a subnet to (optionally) be configured to automatically assign an IPv6 address to the primary network interface of an instance during launch.

  2. We would also like enable ec2 instances to be able to opt to manually assign an IPv6 address to themselves during launch (using the ipv6_address_count from the aws_instance resource or alternatively the ipv6_addresses argument). To do this though, a range of IPv6 addresses must be available in the subnet.

Requirements

At a first look the rough steps to enable this are:

  1. Allow the assign_generated_ipv6_cidr_block argument of the aws_vpc resource to be set by users of the vpc module. This should add an optional variable that will be used by the aws_vpc resource with a default value set to false.
  2. Allow for the subnets to set the ipv6_cidr_block argument using the ipv6_cidr_block output from the aws_vpc resource in the vpc module.
  3. Allow for the assign_ipv6_address_on_creation to be set in the aws_subnet resources in the subnets module with an optional variable that defaults to false.

References: