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

feat: add support for disabling IGW for public subnets #457

Merged
merged 5 commits into from
Jun 20, 2020
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,12 @@ It is possible to integrate this VPC module with [terraform-aws-transit-gateway
| create\_database\_nat\_gateway\_route | Controls if a nat gateway route should be created to give internet access to the database subnets | `bool` | `false` | no |
| create\_database\_subnet\_group | Controls if database subnet group should be created (n.b. database\_subnets must also be set) | `bool` | `true` | no |
| create\_database\_subnet\_route\_table | Controls if separate route table for database should be created | `bool` | `false` | no |
| create\_egress\_only\_igw | Controls if an Egress Only Internet Gateway is created and its related routes. | `bool` | `true` | no |
| create\_elasticache\_subnet\_group | Controls if elasticache subnet group should be created | `bool` | `true` | no |
| create\_elasticache\_subnet\_route\_table | Controls if separate route table for elasticache should be created | `bool` | `false` | no |
| create\_flow\_log\_cloudwatch\_iam\_role | Whether to create IAM role for VPC Flow Logs | `bool` | `false` | no |
| create\_flow\_log\_cloudwatch\_log\_group | Whether to create CloudWatch log group for VPC Flow Logs | `bool` | `false` | no |
| create\_igw | Controls if an Internet Gateway is created for public subnets and the related routes that connect them. | `bool` | `true` | no |
| create\_redshift\_subnet\_group | Controls if redshift subnet group should be created | `bool` | `true` | no |
| create\_redshift\_subnet\_route\_table | Controls if separate route table for redshift should be created | `bool` | `false` | no |
| create\_vpc | Controls if VPC should be created (it affects almost all resources) | `bool` | `true` | no |
Expand Down
14 changes: 7 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ resource "aws_vpc_dhcp_options_association" "this" {
# Internet Gateway
###################
resource "aws_internet_gateway" "this" {
count = var.create_vpc && length(var.public_subnets) > 0 ? 1 : 0
count = var.create_vpc && var.create_igw && length(var.public_subnets) > 0 ? 1 : 0

vpc_id = local.vpc_id

Expand All @@ -103,7 +103,7 @@ resource "aws_internet_gateway" "this" {
}

resource "aws_egress_only_internet_gateway" "this" {
count = var.create_vpc && var.enable_ipv6 && local.max_subnet_length > 0 ? 1 : 0
count = var.create_vpc && var.create_egress_only_igw && var.enable_ipv6 && local.max_subnet_length > 0 ? 1 : 0

vpc_id = local.vpc_id

Expand Down Expand Up @@ -134,7 +134,7 @@ resource "aws_route_table" "public" {
}

resource "aws_route" "public_internet_gateway" {
count = var.create_vpc && length(var.public_subnets) > 0 ? 1 : 0
count = var.create_vpc && var.create_igw && length(var.public_subnets) > 0 ? 1 : 0

route_table_id = aws_route_table.public[0].id
destination_cidr_block = "0.0.0.0/0"
Expand All @@ -146,7 +146,7 @@ resource "aws_route" "public_internet_gateway" {
}

resource "aws_route" "public_internet_gateway_ipv6" {
count = var.create_vpc && var.enable_ipv6 && length(var.public_subnets) > 0 ? 1 : 0
count = var.create_vpc && var.create_igw && var.enable_ipv6 && length(var.public_subnets) > 0 ? 1 : 0

route_table_id = aws_route_table.public[0].id
destination_ipv6_cidr_block = "::/0"
Expand Down Expand Up @@ -199,7 +199,7 @@ resource "aws_route_table" "database" {
}

resource "aws_route" "database_internet_gateway" {
count = var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route && false == var.create_database_nat_gateway_route ? 1 : 0
count = var.create_vpc && var.create_igw && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route && false == var.create_database_nat_gateway_route ? 1 : 0

route_table_id = aws_route_table.database[0].id
destination_cidr_block = "0.0.0.0/0"
Expand All @@ -223,7 +223,7 @@ resource "aws_route" "database_nat_gateway" {
}

resource "aws_route" "database_ipv6_egress" {
count = var.create_vpc && var.enable_ipv6 && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route ? 1 : 0
count = var.create_vpc && var.create_egress_only_igw && var.enable_ipv6 && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route ? 1 : 0

route_table_id = aws_route_table.database[0].id
destination_ipv6_cidr_block = "::/0"
Expand Down Expand Up @@ -926,7 +926,7 @@ resource "aws_route" "private_nat_gateway" {
}

resource "aws_route" "private_ipv6_egress" {
count = var.create_vpc && var.enable_ipv6 ? length(var.private_subnets) : 0
count = var.create_vpc && var.create_egress_only_igw && var.enable_ipv6 ? length(var.private_subnets) : 0

route_table_id = element(aws_route_table.private.*.id, count.index)
destination_ipv6_cidr_block = "::/0"
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2330,3 +2330,15 @@ variable "flow_log_max_aggregation_interval" {
type = number
default = 600
}

variable "create_igw" {
description = "Controls if an Internet Gateway is created for public subnets and the related routes that connect them."
type = bool
default = true
}

variable "create_egress_only_igw" {
description = "Controls if an Egress Only Internet Gateway is created and its related routes."
type = bool
default = true
}