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

fix: Correctly manage route tables for database subnets when multiple NAT gateways present #518

Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ede928b
fix: Manage route tables for multiple database subnets
y-batsianouski Sep 2, 2020
00c8d59
Merge remote-tracking branch 'y-batsianouski/fix/mange_route_table_fo…
Oct 6, 2020
8a011fe
Merge remote-tracking branch 'upstream/master' into database-route-ta…
Oct 6, 2020
01af5b7
Merge branch 'master' into database-route-tables-nat-gateway-fix
Oct 20, 2020
7010998
Merge branch 'master' into database-route-tables-nat-gateway-fix
Oct 22, 2020
b022bda
Merge branch 'master' into database-route-tables-nat-gateway-fix
Oct 22, 2020
8469051
Merge branch 'master' into database-route-tables-nat-gateway-fix
Nov 4, 2020
c893118
Merge remote-tracking branch 'upstream/master' into database-route-ta…
Nov 4, 2020
51d519b
Merge remote-tracking branch 'origin/database-route-tables-nat-gatewa…
Nov 4, 2020
0ec6430
Merge branch 'master' into database-route-tables-nat-gateway-fix
Nov 14, 2020
3d4d364
Merge remote-tracking branch 'upstream/master' into database-route-ta…
Nov 18, 2020
791db4e
Merge remote-tracking branch 'origin/database-route-tables-nat-gatewa…
Nov 18, 2020
aaf75b0
Merge branch 'master' into database-route-tables-nat-gateway-fix
Jan 29, 2021
8a5aaea
Merge branch 'master' into database-route-tables-nat-gateway-fix
Jan 29, 2021
a8c69c0
Merge branch 'master' into database-route-tables-nat-gateway-fix
Feb 4, 2021
17641f3
Merge branch 'master' into database-route-tables-nat-gateway-fix
Feb 22, 2021
17ad0f4
Merge branch 'master' into database-route-tables-nat-gateway-fix
Feb 22, 2021
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
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,17 @@ resource "aws_route_table" "private" {
# Database routes
#################
resource "aws_route_table" "database" {
count = var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 ? 1 : 0
count = var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 ? var.single_nat_gateway || var.create_database_internet_gateway_route ? 1 : length(var.database_subnets) : 0

vpc_id = local.vpc_id

tags = merge(
{
"Name" = "${var.name}-${var.database_subnet_suffix}"
"Name" = var.single_nat_gateway || var.create_database_internet_gateway_route ? "${var.name}-${var.database_subnet_suffix}" : format(
"%s-${var.database_subnet_suffix}-%s",
var.name,
element(var.azs, count.index),
)
},
var.tags,
var.database_route_table_tags,
Expand All @@ -249,7 +253,7 @@ resource "aws_route" "database_internet_gateway" {
}

resource "aws_route" "database_nat_gateway" {
count = var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && false == var.create_database_internet_gateway_route && var.create_database_nat_gateway_route && var.enable_nat_gateway ? local.nat_gateway_count : 0
count = var.create_vpc && var.create_database_subnet_route_table && length(var.database_subnets) > 0 && false == var.create_database_internet_gateway_route && var.create_database_nat_gateway_route && var.enable_nat_gateway ? var.single_nat_gateway ? 1 : length(var.database_subnets) : 0

route_table_id = element(aws_route_table.database.*.id, count.index)
destination_cidr_block = "0.0.0.0/0"
Expand Down Expand Up @@ -1007,7 +1011,7 @@ resource "aws_route_table_association" "database" {
subnet_id = element(aws_subnet.database.*.id, count.index)
route_table_id = element(
coalescelist(aws_route_table.database.*.id, aws_route_table.private.*.id),
var.single_nat_gateway || var.create_database_subnet_route_table ? 0 : count.index,
var.create_database_subnet_route_table ? var.single_nat_gateway || var.create_database_internet_gateway_route ? 0 : count.index : count.index,
)
}

Expand Down