From ace8c043ac4362dc2e01f50f63095fb97b3575fb Mon Sep 17 00:00:00 2001 From: Andy Bohne Date: Tue, 2 Jul 2024 11:51:30 -0400 Subject: [PATCH 1/2] Fix logic for adding default route on public route tables --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 32239e588..35152ce5e 100644 --- a/main.tf +++ b/main.tf @@ -152,9 +152,9 @@ resource "aws_route_table_association" "public" { } resource "aws_route" "public_internet_gateway" { - count = local.create_public_subnets && var.create_igw ? 1 : 0 + count = local.create_public_subnets && var.create_igw ? length(aws_route_table.public) : 0 - route_table_id = aws_route_table.public[0].id + route_table_id = aws_route_table.public[count.index].id destination_cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.this[0].id @@ -164,9 +164,9 @@ resource "aws_route" "public_internet_gateway" { } resource "aws_route" "public_internet_gateway_ipv6" { - count = local.create_public_subnets && var.create_igw && var.enable_ipv6 ? 1 : 0 + count = local.create_public_subnets && var.create_igw && var.enable_ipv6 ? length(aws_route_table.public) : 0 - route_table_id = aws_route_table.public[0].id + route_table_id = aws_route_table.public[count.index].id destination_ipv6_cidr_block = "::/0" gateway_id = aws_internet_gateway.this[0].id } From e8d7b8a52855087940d865eeaff2854105d404c1 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Sat, 3 Aug 2024 09:07:46 -0500 Subject: [PATCH 2/2] Apply suggestions from code review --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 35152ce5e..9bcee412d 100644 --- a/main.tf +++ b/main.tf @@ -152,7 +152,7 @@ resource "aws_route_table_association" "public" { } resource "aws_route" "public_internet_gateway" { - count = local.create_public_subnets && var.create_igw ? length(aws_route_table.public) : 0 + count = local.create_public_subnets && var.create_igw ? local.num_public_route_tables : 0 route_table_id = aws_route_table.public[count.index].id destination_cidr_block = "0.0.0.0/0" @@ -164,7 +164,7 @@ resource "aws_route" "public_internet_gateway" { } resource "aws_route" "public_internet_gateway_ipv6" { - count = local.create_public_subnets && var.create_igw && var.enable_ipv6 ? length(aws_route_table.public) : 0 + count = local.create_public_subnets && var.create_igw && var.enable_ipv6 ? local.num_public_route_tables : 0 route_table_id = aws_route_table.public[count.index].id destination_ipv6_cidr_block = "::/0"