Skip to content

Commit 0160116

Browse files
committed
adding option to create a route to nat gateway in database subnets
1 parent c9bfc7e commit 0160116

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

main.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ resource "aws_route_table" "database" {
122122
}
123123

124124
resource "aws_route" "database_internet_gateway" {
125-
count = "${var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route ? 1 : 0}"
125+
count = "${var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_internet_gateway_route && !var.create_database_nat_gateway_route ? 1 : 0}"
126126

127127
route_table_id = "${aws_route_table.database.id}"
128128
destination_cidr_block = "0.0.0.0/0"
@@ -133,6 +133,17 @@ resource "aws_route" "database_internet_gateway" {
133133
}
134134
}
135135

136+
resource "aws_route" "database_nat_gateway" {
137+
count = "${var.create_vpc && var.enable_nat_gateway && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && var.create_database_nat_gateway_route && !var.create_database_internet_gateway_route ? local.nat_gateway_count : 0}"
138+
route_table_id = "${element(aws_route_table.private.*.id, count.index)}"
139+
destination_cidr_block = "0.0.0.0/0"
140+
nat_gateway_id = "${element(aws_nat_gateway.this.*.id, count.index)}"
141+
142+
timeouts {
143+
create = "5m"
144+
}
145+
}
146+
136147
#################
137148
# Redshift routes
138149
#################

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ variable "create_database_internet_gateway_route" {
122122
default = false
123123
}
124124

125+
variable "create_database_nat_gateway_route" {
126+
description = "Controls if a nat gateway route should be created to give internet access to the database subnets"
127+
default = false
128+
}
129+
125130
variable "azs" {
126131
description = "A list of availability zones in the region"
127132
default = []

0 commit comments

Comments
 (0)