Skip to content

Commit

Permalink
adding tgw-static-routes module (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
parav24 authored Oct 11, 2024
1 parent ac8628b commit a5970f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions modules/aws/networking/tgw-static-routes/main.tf
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
}


14 changes: 14 additions & 0 deletions modules/aws/networking/tgw-static-routes/variables.tf
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
}

0 comments on commit a5970f2

Please sign in to comment.