Skip to content

Commit 4719da3

Browse files
authored
feat: Optionally update VPC Route Tables for attached VPCs (#35)
1 parent 4742ba7 commit 4719da3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ No modules.
9696
| [aws_ram_resource_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_association) | resource |
9797
| [aws_ram_resource_share.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_share) | resource |
9898
| [aws_ram_resource_share_accepter.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_share_accepter) | resource |
99+
| [aws_route.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource |
99100

100101
## Inputs
101102

main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ locals {
1919
var.tags,
2020
var.tgw_default_route_table_tags,
2121
)
22+
23+
vpc_route_table_destination_cidr = flatten([
24+
for k, v in var.vpc_attachments : [
25+
for rtb_id in lookup(v, "vpc_route_table_ids", []) : {
26+
rtb_id = rtb_id
27+
cidr = v["tgw_destination_cidr"]
28+
}
29+
]
30+
])
2231
}
2332

2433
resource "aws_ec2_transit_gateway" "this" {
@@ -76,6 +85,14 @@ resource "aws_ec2_transit_gateway_route" "this" {
7685
transit_gateway_attachment_id = tobool(lookup(local.vpc_attachments_with_routes[count.index][1], "blackhole", false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0]["key"]].id : null
7786
}
7887

88+
resource "aws_route" "this" {
89+
for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => x.cidr }
90+
91+
route_table_id = each.key
92+
destination_cidr_block = each.value
93+
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
94+
}
95+
7996
###########################################################
8097
# VPC Attachments, route table association and propagation
8198
###########################################################

0 commit comments

Comments
 (0)