-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Issue #16: ipv6 support - add ipv6 support #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
# VPC | ||
###### | ||
resource "aws_vpc" "this" { | ||
cidr_block = "${var.cidr}" | ||
instance_tenancy = "${var.instance_tenancy}" | ||
enable_dns_hostnames = "${var.enable_dns_hostnames}" | ||
enable_dns_support = "${var.enable_dns_support}" | ||
cidr_block = "${var.cidr}" | ||
instance_tenancy = "${var.instance_tenancy}" | ||
enable_dns_hostnames = "${var.enable_dns_hostnames}" | ||
enable_dns_support = "${var.enable_dns_support}" | ||
assign_generated_ipv6_cidr_block = "${var.enable_ipv6}" | ||
|
||
tags = "${merge(var.tags, map("Name", format("%s", var.name)))}" | ||
} | ||
|
@@ -41,6 +42,14 @@ resource "aws_route" "public_internet_gateway" { | |
gateway_id = "${aws_internet_gateway.this.id}" | ||
} | ||
|
||
resource "aws_route" "public_internet_gateway_ipv6" { | ||
count = "${var.enable_ipv6 && length(var.public_subnets) > 0 ? 1 : 0}" | ||
|
||
route_table_id = "${aws_route_table.public.id}" | ||
destination_ipv6_cidr_block = "::/0" | ||
gateway_id = "${aws_internet_gateway.this.id}" | ||
} | ||
|
||
################# | ||
# Private routes | ||
################# | ||
|
@@ -57,7 +66,7 @@ resource "aws_route_table" "private" { | |
# Public subnet | ||
################ | ||
resource "aws_subnet" "public" { | ||
count = "${length(var.public_subnets)}" | ||
count = "${!var.enable_ipv6 ? length(var.public_subnets) : 0}" | ||
|
||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.public_subnets[count.index]}" | ||
|
@@ -67,11 +76,24 @@ resource "aws_subnet" "public" { | |
tags = "${merge(var.tags, var.public_subnet_tags, map("Name", format("%s-public-%s", var.name, element(var.azs, count.index))))}" | ||
} | ||
|
||
resource "aws_subnet" "public_ipv6" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making Follow up questions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Anton, To address your questions directly:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification. I want to try the code in this PR and see if I can make something around 1 and 2 during Monday evening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @antonbabenko looks like there was a recently submitted PR that would fix the issue we are seeing. If we wait until this is fixed we won't need to create conditional subnet resources. Additionally, it looks like there is a "fix" coming in 0.11.x (see 0.11.0-beta1 changelog) that may cause this PR code to break because of the new I'm thinking we can sit on this until that PR is merged and I can refactor the ipv6 support into the existing the resources, and hopefully at the same time provide forward compatibility. Let me know your thoughts :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great finding! Absolutely, let's wait for this PR. Terraform AWS provider is the best place to fix this kind of issues. |
||
count = "${var.enable_ipv6 ? length(var.public_subnets) : 0}" | ||
|
||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.public_subnets[count.index]}" | ||
ipv6_cidr_block = "${cidrsubnet(aws_vpc.this.ipv6_cidr_block,8,count.index)}" | ||
availability_zone = "${element(var.azs, count.index)}" | ||
map_public_ip_on_launch = "${var.map_public_ip_on_launch}" | ||
assign_ipv6_address_on_creation = "${var.assign_ipv6_address_on_creation}" | ||
|
||
tags = "${merge(var.tags, var.public_subnet_tags, map("Name", format("%s-public-%s", var.name, element(var.azs, count.index))))}" | ||
} | ||
|
||
################# | ||
# Private subnet | ||
################# | ||
resource "aws_subnet" "private" { | ||
count = "${length(var.private_subnets)}" | ||
count = "${!var.enable_ipv6 ? length(var.private_subnets) : 0}" | ||
|
||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.private_subnets[count.index]}" | ||
|
@@ -80,6 +102,18 @@ resource "aws_subnet" "private" { | |
tags = "${merge(var.tags, var.private_subnet_tags, map("Name", format("%s-private-%s", var.name, element(var.azs, count.index))))}" | ||
} | ||
|
||
resource "aws_subnet" "private_ipv6" { | ||
count = "${var.enable_ipv6 ? length(var.private_subnets) : 0}" | ||
|
||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.private_subnets[count.index]}" | ||
ipv6_cidr_block = "${cidrsubnet(aws_vpc.this.ipv6_cidr_block,8,count.index+32)}" | ||
availability_zone = "${element(var.azs, count.index)}" | ||
assign_ipv6_address_on_creation = "${var.assign_ipv6_address_on_creation}" | ||
|
||
tags = "${merge(var.tags, var.private_subnet_tags, map("Name", format("%s-private-%s", var.name, element(var.azs, count.index))))}" | ||
} | ||
|
||
################## | ||
# Database subnet | ||
################## | ||
|
@@ -144,6 +178,12 @@ resource "aws_nat_gateway" "this" { | |
depends_on = ["aws_internet_gateway.this"] | ||
} | ||
|
||
resource "aws_egress_only_internet_gateway" "this" { | ||
count = "${var.enable_ipv6 ? 1 : 0}" | ||
|
||
vpc_id = "${aws_vpc.this.id}" | ||
} | ||
|
||
resource "aws_route" "private_nat_gateway" { | ||
count = "${var.enable_nat_gateway ? length(var.azs) : 0}" | ||
|
||
|
@@ -152,6 +192,14 @@ resource "aws_route" "private_nat_gateway" { | |
nat_gateway_id = "${element(aws_nat_gateway.this.*.id, count.index)}" | ||
} | ||
|
||
resource "aws_route" "private_nat_gateway_ipv6" { | ||
count = "${var.enable_ipv6 ? length(var.azs) : 0}" | ||
|
||
route_table_id = "${element(aws_route_table.private.*.id, count.index)}" | ||
destination_ipv6_cidr_block = "::/0" | ||
egress_only_gateway_id = "${aws_egress_only_internet_gateway.this.id}" | ||
} | ||
|
||
###################### | ||
# VPC Endpoint for S3 | ||
###################### | ||
|
@@ -216,12 +264,19 @@ resource "aws_vpc_endpoint_route_table_association" "public_dynamodb" { | |
# Route table association | ||
########################## | ||
resource "aws_route_table_association" "private" { | ||
count = "${length(var.private_subnets)}" | ||
count = "${!var.enable_ipv6 ? length(var.private_subnets) : 0}" | ||
|
||
subnet_id = "${element(aws_subnet.private.*.id, count.index)}" | ||
route_table_id = "${element(aws_route_table.private.*.id, count.index)}" | ||
} | ||
|
||
resource "aws_route_table_association" "private_ipv6" { | ||
count = "${var.enable_ipv6 ? length(var.private_subnets) : 0}" | ||
|
||
subnet_id = "${element(aws_subnet.private_ipv6.*.id, count.index)}" | ||
route_table_id = "${element(aws_route_table.private.*.id, count.index)}" | ||
} | ||
|
||
resource "aws_route_table_association" "database" { | ||
count = "${length(var.database_subnets)}" | ||
|
||
|
@@ -237,8 +292,15 @@ resource "aws_route_table_association" "elasticache" { | |
} | ||
|
||
resource "aws_route_table_association" "public" { | ||
count = "${length(var.public_subnets)}" | ||
count = "${!var.enable_ipv6 ? length(var.public_subnets) : 0}" | ||
|
||
subnet_id = "${element(aws_subnet.public.*.id, count.index)}" | ||
route_table_id = "${aws_route_table.public.id}" | ||
} | ||
|
||
resource "aws_route_table_association" "public_ipv6" { | ||
count = "${var.enable_ipv6 ? length(var.public_subnets) : 0}" | ||
|
||
subnet_id = "${element(aws_subnet.public_ipv6.*.id, count.index)}" | ||
route_table_id = "${aws_route_table.public.id}" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep empty line before
tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in latest commit