Skip to content
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

add flag for ipv6 #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "aws_vpc" "default" {
cidr_block = var.cidr_block
enable_dns_support = true
enable_dns_hostnames = true
assign_generated_ipv6_cidr_block = true
assign_generated_ipv6_cidr_block = var.ipv6_enabled

tags = merge(
{
Expand Down Expand Up @@ -61,7 +61,7 @@ resource "aws_route" "private" {


resource "aws_route" "ipv6_private" {
count = length(var.private_subnet_cidr_blocks)
count = var.ipv6_enabled ? length(var.private_subnet_cidr_blocks) : 0

route_table_id = aws_route_table.private[count.index].id
destination_ipv6_cidr_block = "::/0"
Expand All @@ -86,6 +86,7 @@ resource "aws_route" "public" {
}

resource "aws_route" "ipv6_public" {
count = var.ipv6_enabled ? 1 : 0
route_table_id = aws_route_table.public.id
destination_ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.default.id
Expand All @@ -95,12 +96,12 @@ resource "aws_subnet" "private" {
count = length(var.private_subnet_cidr_blocks)

vpc_id = aws_vpc.default.id
assign_ipv6_address_on_creation = true
assign_ipv6_address_on_creation = var.ipv6_enabled
cidr_block = var.private_subnet_cidr_blocks[count.index]
enable_dns64 = true
enable_resource_name_dns_aaaa_record_on_launch = true
enable_resource_name_dns_a_record_on_launch = true
ipv6_cidr_block = cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, var.private_subnet_ipv6_prefix_indices[count.index])
ipv6_cidr_block = var.ipv6_enabled ? cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, var.private_subnet_ipv6_prefix_indices[count.index]) : null
availability_zone = var.availability_zones[count.index]
private_dns_hostname_type_on_launch = "resource-name"

Expand All @@ -116,12 +117,12 @@ resource "aws_subnet" "public" {
count = length(var.public_subnet_cidr_blocks)

vpc_id = aws_vpc.default.id
assign_ipv6_address_on_creation = true
assign_ipv6_address_on_creation = var.ipv6_enabled
cidr_block = var.public_subnet_cidr_blocks[count.index]
enable_dns64 = true
enable_resource_name_dns_aaaa_record_on_launch = true
enable_resource_name_dns_a_record_on_launch = true
ipv6_cidr_block = cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, var.public_subnet_ipv6_prefix_indices[count.index])
ipv6_cidr_block = var.ipv6_enabled ? cidrsubnet(aws_vpc.default.ipv6_cidr_block, 8, var.public_subnet_ipv6_prefix_indices[count.index]) : null
availability_zone = var.availability_zones[count.index]
map_public_ip_on_launch = true
private_dns_hostname_type_on_launch = "resource-name"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ variable "public_subnet_cidr_blocks" {
description = "A list of CIDR ranges for public subnets."
}

variable "ipv6_enabled" {
type = bool
default = true
description = "value"
}

variable "public_subnet_ipv6_prefix_indices" {
type = list(number)
default = [0, 2]
Expand Down
Loading