Skip to content

Commit

Permalink
Use a single route table for all private subnets
Browse files Browse the repository at this point in the history
Now that we are no longer using a separate NAT gateway for each
private subnet, the private subnets' route tables are all the same.
  • Loading branch information
jsf9k committed Jan 21, 2021
1 parent 6b091f0 commit a16b36a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions private_routing.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
# defined in operations_routing.tf.
# -------------------------------------------------------------------------------

# Each private subnet gets its own routing table, since each subnet
# uses its own NAT gateway.
resource "aws_route_table" "private_route_tables" {
# The private subnets can all share a single routing table. Normally
# we would assign each subnet its own NAT gateway, which would require
# separate routing tables, but in this case we do not create any NAT
# gateways since nothing in the private subnets requires access to the
# internet outside the VPC.
resource "aws_route_table" "private_route_table" {
provider = aws.provisionassessment

for_each = toset(var.private_subnet_cidr_blocks)

tags = var.tags
vpc_id = aws_vpc.assessment.id
}
Expand All @@ -27,19 +28,17 @@ resource "aws_route_table" "private_route_tables" {
resource "aws_route" "cool_routes" {
provider = aws.provisionassessment

for_each = toset(var.private_subnet_cidr_blocks)

route_table_id = aws_route_table.private_route_tables[each.value].id
route_table_id = aws_route_table.private_route_table.id
destination_cidr_block = local.cool_shared_services_cidr_block
transit_gateway_id = local.transit_gateway_id
}

# Associate the routing tables with the subnets
# Associate the routing table with the subnets
resource "aws_route_table_association" "private_route_table_associations" {
provider = aws.provisionassessment

for_each = toset(var.private_subnet_cidr_blocks)

subnet_id = aws_subnet.private[each.value].id
route_table_id = aws_route_table.private_route_tables[each.value].id
route_table_id = aws_route_table.private_route_table.id
}

0 comments on commit a16b36a

Please sign in to comment.