Skip to content

Commit 20c4dc4

Browse files
feat: Allow creating VPC routes for already existing or shared TGW (#114)
Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
1 parent 4084879 commit 20c4dc4

File tree

9 files changed

+25
-18
lines changed

9 files changed

+25
-18
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.77.0
3+
rev: v1.83.6
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,7 +23,7 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.4.0
26+
rev: v4.5.0
2727
hooks:
2828
- id: check-merge-conflict
2929
- id: end-of-file-fixer

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ No modules.
104104
|------|-------------|------|---------|:--------:|
105105
| <a name="input_amazon_side_asn"></a> [amazon\_side\_asn](#input\_amazon\_side\_asn) | The Autonomous System Number (ASN) for the Amazon side of the gateway. By default the TGW is created with the current default Amazon ASN. | `string` | `null` | no |
106106
| <a name="input_create_tgw"></a> [create\_tgw](#input\_create\_tgw) | Controls if TGW should be created (it affects almost all resources) | `bool` | `true` | no |
107+
| <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 |
107108
| <a name="input_description"></a> [description](#input\_description) | Description of the EC2 Transit Gateway | `string` | `null` | no |
108109
| <a name="input_enable_auto_accept_shared_attachments"></a> [enable\_auto\_accept\_shared\_attachments](#input\_enable\_auto\_accept\_shared\_attachments) | Whether resource attachment requests are automatically accepted | `bool` | `false` | no |
109110
| <a name="input_enable_default_route_table_association"></a> [enable\_default\_route\_table\_association](#input\_enable\_default\_route\_table\_association) | Whether resource attachments are automatically associated with the default association route table | `bool` | `true` | no |
@@ -125,7 +126,6 @@ No modules.
125126
| <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 |
126127
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the transit gateway | `map(string)` | `{}` | no |
127128
| <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 |
129129
| <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 |
130130
| <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 |
131131

examples/complete/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Note that this example may create resources which cost money. Run `terraform des
1919

2020
| Name | Version |
2121
|------|---------|
22-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
2323
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.4 |
2424

2525
## Providers
@@ -31,8 +31,8 @@ No providers.
3131
| Name | Source | Version |
3232
|------|--------|---------|
3333
| <a name="module_tgw"></a> [tgw](#module\_tgw) | ../../ | n/a |
34-
| <a name="module_vpc1"></a> [vpc1](#module\_vpc1) | terraform-aws-modules/vpc/aws | ~> 3.0 |
35-
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | ~> 3.0 |
34+
| <a name="module_vpc1"></a> [vpc1](#module\_vpc1) | terraform-aws-modules/vpc/aws | ~> 5.0 |
35+
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | ~> 5.0 |
3636

3737
## Resources
3838

examples/complete/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module "tgw" {
8383

8484
module "vpc1" {
8585
source = "terraform-aws-modules/vpc/aws"
86-
version = "~> 3.0"
86+
version = "~> 5.0"
8787

8888
name = "${local.name}-vpc1"
8989
cidr = "10.10.0.0/16"
@@ -100,7 +100,7 @@ module "vpc1" {
100100

101101
module "vpc2" {
102102
source = "terraform-aws-modules/vpc/aws"
103-
version = "~> 3.0"
103+
version = "~> 5.0"
104104

105105
name = "${local.name}-vpc2"
106106
cidr = "10.20.0.0/16"

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {

examples/multi-account/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Note that this example may create resources which cost money. Run `terraform des
1919

2020
| Name | Version |
2121
|------|---------|
22-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
2323
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.4 |
2424

2525
## Providers
@@ -32,8 +32,8 @@ No providers.
3232
|------|--------|---------|
3333
| <a name="module_tgw"></a> [tgw](#module\_tgw) | ../../ | n/a |
3434
| <a name="module_tgw_peer"></a> [tgw\_peer](#module\_tgw\_peer) | ../../ | n/a |
35-
| <a name="module_vpc1"></a> [vpc1](#module\_vpc1) | terraform-aws-modules/vpc/aws | ~> 3.0 |
36-
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | ~> 3.0 |
35+
| <a name="module_vpc1"></a> [vpc1](#module\_vpc1) | terraform-aws-modules/vpc/aws | ~> 5.0 |
36+
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | ~> 5.0 |
3737

3838
## Resources
3939

examples/multi-account/main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ module "tgw_peer" {
104104
transit_gateway_default_route_table_association = false
105105
transit_gateway_default_route_table_propagation = false
106106

107+
vpc_route_table_ids = module.vpc1.private_route_table_ids
108+
tgw_destination_cidr = "0.0.0.0/0"
109+
107110
tgw_routes = [
108111
{
109112
destination_cidr_block = "30.0.0.0/16"
@@ -128,7 +131,7 @@ module "tgw_peer" {
128131

129132
module "vpc1" {
130133
source = "terraform-aws-modules/vpc/aws"
131-
version = "~> 3.0"
134+
version = "~> 5.0"
132135

133136
name = "${local.name}-vpc1"
134137
cidr = "10.10.0.0/16"
@@ -146,7 +149,7 @@ module "vpc1" {
146149

147150
module "vpc2" {
148151
source = "terraform-aws-modules/vpc/aws"
149-
version = "~> 3.0"
152+
version = "~> 5.0"
150153

151154
providers = {
152155
aws = aws.peer

examples/multi-account/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.13.1"
2+
required_version = ">= 1.0"
33

44
required_providers {
55
aws = {

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ locals {
1515
for rtb_id in try(v.vpc_route_table_ids, []) : {
1616
rtb_id = rtb_id
1717
cidr = v.tgw_destination_cidr
18+
tgw_id = var.create_tgw ? aws_ec2_transit_gateway.this[0].id : v.tgw_id
1819
}
1920
]
2021
])
@@ -110,11 +111,14 @@ resource "aws_ec2_transit_gateway_route" "this" {
110111
}
111112

112113
resource "aws_route" "this" {
113-
for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => x.cidr }
114+
for_each = { for x in local.vpc_route_table_destination_cidr : x.rtb_id => {
115+
cidr = x.cidr,
116+
tgw_id = x.tgw_id
117+
} }
114118

115119
route_table_id = each.key
116-
destination_cidr_block = each.value
117-
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
120+
destination_cidr_block = each.value["cidr"]
121+
transit_gateway_id = each.value["tgw_id"]
118122
}
119123

120124
resource "aws_ec2_transit_gateway_route_table_association" "this" {

0 commit comments

Comments
 (0)