aws-ia / terraform-aws-vpc

AWS VPC Module
https://registry.terraform.io/modules/aws-ia/vpc/aws/latest
Apache License 2.0
82 stars 89 forks source link

Dual Stack subnets - assign_ipv6_address_on_creation attribute doesn't work. #148

Open SpaghettiKat45 opened 2 months ago

SpaghettiKat45 commented 2 months ago

Changing the 'assign_ipv6_address_on_creation' between true and false has no effect. This means that when trying to build a Fargate backed cluster for EKS I cannot use the dual stack subnet as it is not auto assigning ipv6 addresses to the ENIs.

Additionally, I don't see any setting in the module to enable dns64 for the dual stack subnets which would also be helpful. Let me know if there is something I am missing.

subnets = {
    # Transit gateway subnets (dual-stack)
    transit_gateway = {
      netmask                                         = 28
      assign_ipv6_cidr                                = true
      connect_to_public_natgw                         = false
      transit_gateway_default_route_table_association = false
      transit_gateway_default_route_table_propagation = true
      transit_gateway_appliance_mode_support          = "enable"
      transit_gateway_dns_support = "enable"
    }
    # Node/Pod Network subnets (dual-stack)
    workload = {
      netmask                         = 24
      assign_ipv6_cidr                = true
      assign_ipv6_address_on_creation = true
      connect_to_public_natgw         = false
    }
  }
SpaghettiKat45 commented 2 months ago

Looks like it should be updated to the following in main.tf line 231 - 253

resource "aws_subnet" "private" {
  for_each = toset(try(local.private_per_az, []))

  availability_zone                              = split("/", each.key)[1]
  vpc_id                                         = local.vpc.id
  cidr_block                                     = can(local.calculated_subnets[split("/", each.key)[0]][split("/", each.key)[1]]) ? local.calculated_subnets[split("/", each.key)[0]][split("/", each.key)[1]] : null
  ipv6_cidr_block                                = can(local.calculated_subnets_ipv6[split("/", each.key)[0]][split("/", each.key)[1]]) ? local.calculated_subnets_ipv6[split("/", each.key)[0]][split("/", each.key)[1]] : null
  ipv6_native                                    = contains(local.subnets_with_ipv6_native, split("/", each.key)[0]) ? true : false
  map_public_ip_on_launch                        = contains(local.subnets_with_ipv6_native, split("/", each.key)[0]) ? null : false
  assign_ipv6_address_on_creation                = contains(local.subnets_with_ipv6_native, split("/", each.key)[0]) ? true : try(var.subnets[split("/", each.key)[0]].assign_ipv6_address_on_creation, false)
  enable_resource_name_dns_aaaa_record_on_launch = contains(local.subnets_with_ipv6_native, split("/", each.key)[0]) ? true : try(var.subnets[split("/", each.key)[0]].enable_resource_name_dns_aaaa_record_on_launch, false)
  enable_dns64                                   = try(var.subnets[split("/", each.key)[0]].enable_dns64, false)

  tags = merge(
    { Name = "${local.subnet_names[split("/", each.key)[0]]}-${split("/", each.key)[1]}" },
    module.tags.tags_aws,
    try(module.subnet_tags[split("/", each.key)[0]].tags_aws, {})
  )

  depends_on = [
    aws_vpc_ipv4_cidr_block_association.secondary
  ]
}