Skip to content

Commit d38a736

Browse files
author
Kamil Hristov
committed
Allow creating VPC routes for already existing or shared TGW
1 parent e522e72 commit d38a736

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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)