Skip to content

Commit 51fcf60

Browse files
Enable IPv6
1 parent f195c64 commit 51fcf60

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

terraform/main.tf

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ provider "aws" {
2121

2222
# VPC and networking
2323
resource "aws_vpc" "main" {
24-
cidr_block = "10.0.0.0/16"
25-
enable_dns_hostnames = true
26-
enable_dns_support = true
24+
cidr_block = "10.0.0.0/16"
25+
assign_generated_ipv6_cidr_block = true
26+
enable_dns_hostnames = true
27+
enable_dns_support = true
2728

2829
tags = {
2930
Name = "${var.project_name}-vpc"
3031
}
3132
}
3233

3334
resource "aws_subnet" "public" {
34-
count = 2
35-
vpc_id = aws_vpc.main.id
36-
cidr_block = "10.0.${count.index + 1}.0/24"
37-
availability_zone = data.aws_availability_zones.available.names[count.index]
38-
map_public_ip_on_launch = true
35+
count = 2
36+
vpc_id = aws_vpc.main.id
37+
cidr_block = "10.0.${count.index + 1}.0/24"
38+
ipv6_cidr_block = cidrsubnet(aws_vpc.main.ipv6_cidr_block, 8, count.index + 1)
39+
availability_zone = data.aws_availability_zones.available.names[count.index]
40+
map_public_ip_on_launch = true
41+
assign_ipv6_address_on_creation = true
3942

4043
tags = {
4144
Name = "${var.project_name}-public-${count.index + 1}"
@@ -58,6 +61,11 @@ resource "aws_route_table" "public" {
5861
gateway_id = aws_internet_gateway.main.id
5962
}
6063

64+
route {
65+
ipv6_cidr_block = "::/0"
66+
gateway_id = aws_internet_gateway.main.id
67+
}
68+
6169
tags = {
6270
Name = "${var.project_name}-public-rt"
6371
}

0 commit comments

Comments
 (0)