Skip to content

Commit 1661dfa

Browse files
authored
feat: Make TGW routing creation optional (#119)
1 parent e522e72 commit 1661dfa

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ No modules.
125125
| <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 |
126126
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the transit gateway | `map(string)` | `{}` | no |
127127
| <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 |
128+
| <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 |
128129
| <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 |
129130
| <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 |
130131

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
8888
################################################################################
8989

9090
resource "aws_ec2_transit_gateway_route_table" "this" {
91-
count = var.create_tgw ? 1 : 0
91+
count = var.create_tgw && var.create_tgw_routes ? 1 : 0
9292

9393
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
9494

@@ -100,7 +100,7 @@ resource "aws_ec2_transit_gateway_route_table" "this" {
100100
}
101101

102102
resource "aws_ec2_transit_gateway_route" "this" {
103-
count = length(local.vpc_attachments_with_routes)
103+
count = var.create_tgw_routes ? length(local.vpc_attachments_with_routes) : 0
104104

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

120120
resource "aws_ec2_transit_gateway_route_table_association" "this" {
121121
for_each = {
122-
for k, v in var.vpc_attachments : k => v if var.create_tgw && try(v.transit_gateway_default_route_table_association, true) != true
122+
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
123123
}
124124

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

130130
resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
131131
for_each = {
132-
for k, v in var.vpc_attachments : k => v if var.create_tgw && try(v.transit_gateway_default_route_table_propagation, true) != true
132+
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
133133
}
134134

135135
# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ variable "tgw_vpc_attachment_tags" {
112112
# Route Table / Routes
113113
################################################################################
114114

115+
variable "create_tgw_routes" {
116+
description = "Controls if TGW Route Table / Routes should be created"
117+
type = bool
118+
default = true
119+
}
120+
115121
variable "transit_gateway_route_table_id" {
116122
description = "Identifier of EC2 Transit Gateway Route Table to use with the Target Gateway when reusing it between multiple TGWs"
117123
type = string

0 commit comments

Comments
 (0)