From 7515f9c847fcf7155479df4e0abbad0ef0f0ff6d Mon Sep 17 00:00:00 2001 From: Venkata Para Date: Fri, 11 Oct 2024 12:25:05 +0100 Subject: [PATCH 1/2] adding tgw-static-routes module --- .../aws/networking/tgw-static-routes/main.tf | 25 +++++++++++++++++++ .../networking/tgw-static-routes/variables.tf | 14 +++++++++++ 2 files changed, 39 insertions(+) create mode 100644 modules/aws/networking/tgw-static-routes/main.tf create mode 100644 modules/aws/networking/tgw-static-routes/variables.tf diff --git a/modules/aws/networking/tgw-static-routes/main.tf b/modules/aws/networking/tgw-static-routes/main.tf new file mode 100644 index 0000000..c39635c --- /dev/null +++ b/modules/aws/networking/tgw-static-routes/main.tf @@ -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 +} + + diff --git a/modules/aws/networking/tgw-static-routes/variables.tf b/modules/aws/networking/tgw-static-routes/variables.tf new file mode 100644 index 0000000..7ced358 --- /dev/null +++ b/modules/aws/networking/tgw-static-routes/variables.tf @@ -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 +} \ No newline at end of file From 7932d2cf2e637041b36ff979274668443aafd79e Mon Sep 17 00:00:00 2001 From: Venkata Para Date: Mon, 14 Oct 2024 10:51:53 +0100 Subject: [PATCH 2/2] updated input file format from json to yaml --- modules/aws/networking/tgw-static-routes/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/aws/networking/tgw-static-routes/main.tf b/modules/aws/networking/tgw-static-routes/main.tf index c39635c..f821786 100644 --- a/modules/aws/networking/tgw-static-routes/main.tf +++ b/modules/aws/networking/tgw-static-routes/main.tf @@ -10,7 +10,7 @@ data "aws_ec2_transit_gateway_route_table" "tgw_rt" { # Read routes from the text file (routes.json) locals { - routes = jsondecode(var.static_routes_file) + routes = yamldecode(var.static_routes_file) } # Add static routes to the TGW route table using the data from the text file