region-host group: fall back to the VPC's main route table
Group mode looked each zone's route table up by subnet association. Default-VPC subnets have no explicit association, they use the main table implicitly, so the dev plan failed with "no matching Route Table found" for both zones (P3b-1 card item 1). Look for an explicit association first and fall back to the VPC's main table. Tests: two mock runs (implicit main table, explicit wins), full module suite 43+2 passed on OpenTofu 1.13.1, plan-gate tests 30 OK.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+56
−3
infra/modules/region-host/group.tf+22 −3infra/modules/region-host/tests/group.tftest.hcl+34 −0
CI failed — run details
diff --git a/infra/modules/region-host/group.tf b/infra/modules/region-host/group.tf| index d56876b17..a40a4efa9 100644 |
| --- a/infra/modules/region-host/group.tf |
| +++ b/infra/modules/region-host/group.tf |
| @@ -58,10 +58,29 @@ data "aws_subnets" "group" { |
| } |
| } |
| +# A subnet with no explicit route table association (every default-VPC |
| +# subnet) uses the VPC's main table, which a subnet-id lookup never finds. |
| +data "aws_route_tables" "group_explicit" { |
| + for_each = local.group_enabled ? var.group_zones : {} |
| + vpc_id = var.vpc_id |
| + filter { |
| + name = "association.subnet-id" |
| + values = [each.value.subnet_id] |
| + } |
| +} |
| + |
| +data "aws_route_table" "group_main" { |
| + count = local.group_enabled ? 1 : 0 |
| + vpc_id = var.vpc_id |
| + filter { |
| + name = "association.main" |
| + values = ["true"] |
| + } |
| +} |
| + |
| data "aws_route_table" "group" { |
| - for_each = local.group_enabled ? var.group_zones : {} |
| - subnet_id = each.value.subnet_id |
| - vpc_id = var.vpc_id |
| + for_each = local.group_enabled ? var.group_zones : {} |
| + route_table_id = length(data.aws_route_tables.group_explicit[each.key].ids) > 0 ? data.aws_route_tables.group_explicit[each.key].ids[0] : data.aws_route_table.group_main[0].id |
| } |
| data "aws_lb" "group" { |
diff --git a/infra/modules/region-host/tests/group.tftest.hcl b/infra/modules/region-host/tests/group.tftest.hcl| index 43dfb0936..d8cbe0076 100644 |
| --- a/infra/modules/region-host/tests/group.tftest.hcl |
| +++ b/infra/modules/region-host/tests/group.tftest.hcl |
| @@ -359,6 +359,40 @@ run "private_subnets" { |
| } |
| expect_failures = [aws_security_group.group] |
| } |
| +run "implicit_main_route_table" { |
| + command = plan |
| + override_data { |
| + target = data.aws_route_tables.group_explicit |
| + values = { ids = [] } |
| + } |
| + override_data { |
| + target = data.aws_route_table.group_main |
| + values = { id = "rtb-0000000000000main" } |
| + } |
| + assert { |
| + condition = alltrue([for table in data.aws_route_table.group : table.route_table_id == "rtb-0000000000000main"]) |
| + error_message = "a subnet with no explicit association must use the VPC's main route table" |
| + } |
| +} |
| +run "explicit_route_table" { |
| + command = plan |
| + override_data { |
| + target = data.aws_route_tables.group_explicit["eu-west-1a"] |
| + values = { ids = ["rtb-00000000000000001"] } |
| + } |
| + override_data { |
| + target = data.aws_route_tables.group_explicit["eu-west-1b"] |
| + values = { ids = [] } |
| + } |
| + override_data { |
| + target = data.aws_route_table.group_main |
| + values = { id = "rtb-0000000000000main" } |
| + } |
| + assert { |
| + condition = data.aws_route_table.group["eu-west-1a"].route_table_id == "rtb-00000000000000001" && data.aws_route_table.group["eu-west-1b"].route_table_id == "rtb-0000000000000main" |
| + error_message = "an explicit subnet association wins over the main route table" |
| + } |
| +} |
| run "wrong_vpc_target_group" { |
| command = plan |
| override_data { |