Skip to content

Commit

Permalink
Improved public route readability
Browse files Browse the repository at this point in the history
  • Loading branch information
code-rius committed Nov 30, 2023
1 parent 0cdf471 commit affae23
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ locals {

internet_gateway_count = (var.create_internet_gateway && length(var.public_subnet_cidrs) > 0) ? 1 : 0
egress_only_internet_gateway_count = (var.create_egress_only_internet_gateway && length(var.private_subnet_cidrs) > 0) ? 1 : 0
public_route_count = var.individual_public_subnet_routing ? length(var.public_subnet_cidrs) : local.internet_gateway_count
}

resource "aws_vpc" "main" {
Expand Down Expand Up @@ -61,23 +62,23 @@ resource "aws_route_table" "public" {
}

resource "aws_route" "public" {
count = var.individual_public_subnet_routing ? length(var.public_subnet_cidrs) : local.internet_gateway_count
count = local.public_route_count
depends_on = [
aws_internet_gateway.public,
aws_route_table.public,
]
route_table_id = var.individual_public_subnet_routing ? aws_route_table.public[count.index].id : aws_route_table.public[0].id
route_table_id = aws_route_table.public[count.index].id
gateway_id = aws_internet_gateway.public[0].id
destination_cidr_block = "0.0.0.0/0"
}

resource "aws_route" "ipv6-public" {
count = var.individual_public_subnet_routing ? length(var.public_subnet_cidrs) : local.internet_gateway_count
count = local.public_route_count
depends_on = [
aws_internet_gateway.public,
aws_route_table.public,
]
route_table_id = var.individual_public_subnet_routing ? aws_route_table.public[count.index].id : aws_route_table.public[0].id
route_table_id = aws_route_table.public[count.index].id
gateway_id = aws_internet_gateway.public[0].id
destination_ipv6_cidr_block = "::/0"
}
Expand Down

0 comments on commit affae23

Please sign in to comment.