-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
19 lines (17 loc) · 1002 Bytes
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data "aws_route_table" "this" {
count = length(var.route_table_lookup_tags) > 0 ? 1 : 0
tags = var.route_table_lookup_tags
}
locals {
rtb_ids = concat(data.aws_route_table.this[*].id, var.route_table_ids)
map_of_tables_and_routes = merge(tolist(flatten([for id in local.rtb_ids : {for r in var.routes : "${id}_${r}"=> { rtb_id = id, route = r }}]))...)
map_of_tables_and_prefixes = merge(tolist(flatten([for id in local.rtb_ids : {for pl in var.prefix_list_ids : "${id}_${pl}" => { rtb_id = id, prefix_list_id = pl }}]))...)
merged_routes = merge(local.map_of_tables_and_routes, local.map_of_tables_and_prefixes)
}
resource "aws_route" "to_tgw" {
for_each = local.merged_routes
route_table_id = lookup(each.value, "rtb_id")
transit_gateway_id = var.transit_gateway_id
destination_cidr_block = lookup(each.value, "route", null)
destination_prefix_list_id = lookup(each.value, "prefix_list_id", null)
}