Skip to content

Commit 9e445b0

Browse files
committed
Allow creating VPC routes for already existing or shared TGW
1 parent e522e72 commit 9e445b0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

examples/multi-account/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ module "tgw_peer" {
104104
transit_gateway_default_route_table_association = false
105105
transit_gateway_default_route_table_propagation = false
106106

107+
vpc_route_table_ids = module.vpc1.private_route_table_ids
108+
tgw_destination_cidr = "0.0.0.0/0"
109+
107110
tgw_routes = [
108111
{
109112
destination_cidr_block = "30.0.0.0/16"

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ locals {
1515
for rtb_id in try(v.vpc_route_table_ids, []) : {
1616
rtb_id = rtb_id
1717
cidr = v.tgw_destination_cidr
18+
tgw_id = var.create_tgw ? aws_ec2_transit_gateway.this[0].id : v.tgw_id
1819
}
1920
]
2021
])
@@ -110,11 +111,14 @@ resource "aws_ec2_transit_gateway_route" "this" {
110111
}
111112

112113
resource "aws_route" "this" {
113-
for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => x.cidr }
114+
for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => {
115+
cidr = x.cidr,
116+
tgw_id = x.tgw_id
117+
} }
114118

115119
route_table_id = each.key
116-
destination_cidr_block = each.value
117-
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
120+
destination_cidr_block = each.value["cidr"]
121+
transit_gateway_id = each.value["tgw_id"]
118122
}
119123

120124
resource "aws_ec2_transit_gateway_route_table_association" "this" {

0 commit comments

Comments
 (0)