Skip to content

feat: Make TGW routing creation optional #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ No modules.
| <a name="input_tgw_vpc_attachment_tags"></a> [tgw\_vpc\_attachment\_tags](#input\_tgw\_vpc\_attachment\_tags) | Additional tags for VPC attachments | `map(string)` | `{}` | no |
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the transit gateway | `map(string)` | `{}` | no |
| <a name="input_transit_gateway_cidr_blocks"></a> [transit\_gateway\_cidr\_blocks](#input\_transit\_gateway\_cidr\_blocks) | One or more IPv4 or IPv6 CIDR blocks for the transit gateway. Must be a size /24 CIDR block or larger for IPv4, or a size /64 CIDR block or larger for IPv6 | `list(string)` | `[]` | no |
| <a name="input_create_tgw_routes"></a> [create\_tgw\_routes](#input\_create\_tgw\_routes) | Controls if TGW Route Table / Routes should be created | `bool` | `true` | no |
| <a name="input_transit_gateway_route_table_id"></a> [transit\_gateway\_route\_table\_id](#input\_transit\_gateway\_route\_table\_id) | Identifier of EC2 Transit Gateway Route Table to use with the Target Gateway when reusing it between multiple TGWs | `string` | `null` | no |
| <a name="input_vpc_attachments"></a> [vpc\_attachments](#input\_vpc\_attachments) | Maps of maps of VPC details to attach to TGW. Type 'any' to disable type validation by Terraform. | `any` | `{}` | no |

Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
################################################################################

resource "aws_ec2_transit_gateway_route_table" "this" {
count = var.create_tgw ? 1 : 0
count = var.create_tgw && var.create_tgw_routes ? 1 : 0

transit_gateway_id = aws_ec2_transit_gateway.this[0].id

Expand All @@ -100,7 +100,7 @@ resource "aws_ec2_transit_gateway_route_table" "this" {
}

resource "aws_ec2_transit_gateway_route" "this" {
count = length(local.vpc_attachments_with_routes)
count = var.create_tgw_routes ? length(local.vpc_attachments_with_routes) : 0

destination_cidr_block = local.vpc_attachments_with_routes[count.index][1].destination_cidr_block
blackhole = try(local.vpc_attachments_with_routes[count.index][1].blackhole, null)
Expand All @@ -119,7 +119,7 @@ resource "aws_route" "this" {

resource "aws_ec2_transit_gateway_route_table_association" "this" {
for_each = {
for k, v in var.vpc_attachments : k => v if var.create_tgw && try(v.transit_gateway_default_route_table_association, true) != true
for k, v in var.vpc_attachments : k => v if var.create_tgw && var.create_tgw_routes && try(v.transit_gateway_default_route_table_association, true) != true
}

# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
Expand All @@ -129,7 +129,7 @@ resource "aws_ec2_transit_gateway_route_table_association" "this" {

resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
for_each = {
for k, v in var.vpc_attachments : k => v if var.create_tgw && try(v.transit_gateway_default_route_table_propagation, true) != true
for k, v in var.vpc_attachments : k => v if var.create_tgw && var.create_tgw_routes && try(v.transit_gateway_default_route_table_propagation, true) != true
}

# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ variable "tgw_vpc_attachment_tags" {
# Route Table / Routes
################################################################################

variable "create_tgw_routes" {
description = "Controls if TGW Route Table / Routes should be created"
type = bool
default = true
}

variable "transit_gateway_route_table_id" {
description = "Identifier of EC2 Transit Gateway Route Table to use with the Target Gateway when reusing it between multiple TGWs"
type = string
Expand Down