Commit 2580c9e1 authored by Ilia Lazebnik's avatar Ilia Lazebnik Committed by GitHub

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

parent b0620312
......@@ -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 |
......
......@@ -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
......@@ -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
......@@ -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"
......@@ -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"
......@@ -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"
......@@ -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"
......@@ -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"
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment