Skip to content

Commit

Permalink
Added IPV6
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishgoyal246 committed Jun 19, 2020
1 parent 6df31b7 commit 854b807
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions _example/private-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module "private-subnets" {
type = "private"
nat_gateway_enabled = true
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
public_subnet_ids = ["subnet-XXXXXXXXXXXXX", "subnet-XXXXXXXXXXXXX"]
}
1 change: 1 addition & 0 deletions _example/public-private-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ module "subnets" {
igw_id = module.vpc.igw_id
nat_gateway_enabled = true
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
}
11 changes: 11 additions & 0 deletions _example/public-private-subnet/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ output "public_subnet_cidrs" {
value = module.subnets.public_subnet_cidrs
description = "The CIDR of the subnet."
}

output "public_subnet_cidrs_ipv6" {
value = module.subnets.public_subnet_cidrs_ipv6
description = "The CIDR of the subnet."
}

output "private_subnet_cidrs" {
value = module.subnets.private_subnet_cidrs
description = "The CIDR of the subnet."
}

output "private_subnet_cidrs_ipv6" {
value = module.subnets.private_subnet_cidrs_ipv6
description = "The CIDR of the subnet."
}

output "private_tags" {
value = module.subnets.private_tags
description = "A mapping of tags to assign to the resource."
Expand Down
1 change: 1 addition & 0 deletions _example/public-subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ module "subnets" {
type = "public"
igw_id = module.vpc.igw_id
cidr_block = module.vpc.vpc_cidr_block
ipv6_cidr_block = module.vpc.ipv6_cidr_block
}
5 changes: 5 additions & 0 deletions _example/public-subnet/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ output "public_subnet_cidrs" {
description = "The CIDR of the subnet."
}

output "public_subnet_cidrs_ipv6" {
value = module.subnets.public_subnet_cidrs_ipv6
description = "The CIDR of the subnet."
}

output "public_tags" {
value = module.subnets.public_tags
description = "A mapping of tags to assign to the resource."
Expand Down
61 changes: 61 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ resource "aws_subnet" "public" {
local.public_count + count.index
)

ipv6_cidr_block = cidrsubnet(
signum(length(var.ipv6_cidr_block)) == 1 ? var.ipv6_cidr_block : var.ipv6_cidr_block,
8,
local.public_count + count.index
)

assign_ipv6_address_on_creation = false

tags = merge(
module.public-labels.tags,
{
Expand Down Expand Up @@ -87,6 +95,15 @@ resource "aws_network_acl" "public" {
protocol = "-1"
}

egress {
rule_no = 101
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 0
to_port = 0
protocol = "-1"
}

ingress {
rule_no = 100
action = "allow"
Expand All @@ -96,6 +113,15 @@ resource "aws_network_acl" "public" {
protocol = "-1"
}

ingress {
rule_no = 101
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 0
to_port = 0
protocol = "-1"
}

tags = module.public-labels.tags
depends_on = [aws_subnet.public]
}
Expand Down Expand Up @@ -128,6 +154,15 @@ resource "aws_route" "public" {
depends_on = [aws_route_table.public]
}

resource "aws_route" "public_ipv6" {
count = local.public_count

route_table_id = element(aws_route_table.public.*.id, count.index)
gateway_id = var.igw_id
destination_ipv6_cidr_block = "::/0"
depends_on = [aws_route_table.public]
}

#Module : ROUTE TABLE ASSOCIATION PRIVATE
#Description : Provides a resource to create an association between a subnet and routing
# table.
Expand Down Expand Up @@ -170,6 +205,14 @@ resource "aws_subnet" "private" {
count.index
)

ipv6_cidr_block = cidrsubnet(
signum(length(var.ipv6_cidr_block)) == 1 ? var.ipv6_cidr_block : var.ipv6_cidr_block,
8,
count.index
)

assign_ipv6_address_on_creation = false

tags = merge(
module.private-labels.tags,
{
Expand Down Expand Up @@ -208,6 +251,15 @@ resource "aws_network_acl" "private" {
protocol = "-1"
}

egress {
rule_no = 101
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 0
to_port = 0
protocol = "-1"
}

ingress {
rule_no = 100
action = "allow"
Expand All @@ -217,6 +269,15 @@ resource "aws_network_acl" "private" {
protocol = "-1"
}

ingress {
rule_no = 101
action = "allow"
ipv6_cidr_block = "::/0"
from_port = 0
to_port = 0
protocol = "-1"
}

tags = module.private-labels.tags
depends_on = [aws_subnet.private]
}
Expand Down
10 changes: 10 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ output "public_subnet_cidrs" {
description = "CIDR blocks of the created public subnets."
}

output "public_subnet_cidrs_ipv6" {
value = aws_subnet.public.*.ipv6_cidr_block
description = "CIDR blocks of the created public subnets."
}

output "private_subnet_id" {
value = aws_subnet.private.*.id
description = "The ID of the private subnet."
Expand All @@ -21,6 +26,11 @@ output "private_subnet_cidrs" {
description = "CIDR blocks of the created private subnets."
}

output "private_subnet_cidrs_ipv6" {
value = aws_subnet.private.*.ipv6_cidr_block
description = "CIDR blocks of the created private subnets."
}

output "public_route_tables_id" {
value = aws_route_table.public.*.id
description = "The ID of the routing table."
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ variable "cidr_block" {
description = "Base CIDR block which is divided into subnet CIDR blocks (e.g. `10.0.0.0/16`)."
}

variable "ipv6_cidr_block" {
type = string
description = "Base CIDR block which is divided into subnet CIDR blocks (e.g. `10.0.0.0/16`)."
}

variable "public_subnet_ids" {
type = list(string)
default = []
Expand Down

0 comments on commit 854b807

Please sign in to comment.