-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tgw-static-routes module (#187)
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
# Data resource to fetch the existing TGW route table by name or ID | ||
data "aws_ec2_transit_gateway_route_table" "tgw_rt" { | ||
#id = var.tgw_route_table_id | ||
filter { | ||
name = "tag:Name" | ||
values = [var.tgw_route_table_name] # Can be fetched or passed from Terragrunt | ||
} | ||
} | ||
|
||
# Read routes from the text file (routes.json) | ||
locals { | ||
routes = jsondecode(var.static_routes_file) | ||
} | ||
|
||
# Add static routes to the TGW route table using the data from the text file | ||
resource "aws_ec2_transit_gateway_route" "tgw_routes" { | ||
for_each = { for route in local.routes["routes"] : route.cidr_block => route } | ||
|
||
transit_gateway_route_table_id = data.aws_ec2_transit_gateway_route_table.tgw_rt.id | ||
destination_cidr_block = each.value.cidr_block | ||
transit_gateway_attachment_id = each.value.transit_gateway_attachment_id | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
variable "tgw_route_table_id" { | ||
description = "The Transit Gateway Route Table ID." | ||
type = string | ||
} | ||
|
||
variable "tgw_route_table_name" { | ||
description = "The Transit Gateway Route Table Name." | ||
type = string | ||
} | ||
|
||
variable static_routes_file { | ||
description = "A list of static routes to supply in a file" | ||
type = string | ||
} |