Skip to content

Commit 0f6b38e

Browse files
author
Gert van den Berg
committed
Add support for specifying the region for version 6+ of the AWS provider
1 parent 01789bd commit 0f6b38e

File tree

10 files changed

+165
-3
lines changed

10 files changed

+165
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
### Features
8+
9+
* Add a region parameter to allow a single provider to be used for multiple regions, as supported in version 6.0.0+ of the AWS provider.
10+
511
## [2.13.0](https://github.com/terraform-aws-modules/terraform-aws-transit-gateway/compare/v2.12.2...v2.13.0) (2025-01-15)
612

713

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ module "vpc" {
6969
| Name | Version |
7070
|------|---------|
7171
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
72-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.4 |
72+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 6.0 |
7373

7474
## Providers
7575

7676
| Name | Version |
7777
|------|---------|
78-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.4 |
78+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 6.0 |
7979

8080
## Modules
8181

@@ -119,6 +119,7 @@ No modules.
119119
| <a name="input_ram_principals"></a> [ram\_principals](#input\_ram\_principals) | A list of principals to share TGW with. Possible values are an AWS account ID, an AWS Organizations Organization ARN, or an AWS Organizations Organization Unit ARN | `list(string)` | `[]` | no |
120120
| <a name="input_ram_resource_share_arn"></a> [ram\_resource\_share\_arn](#input\_ram\_resource\_share\_arn) | ARN of RAM resource share | `string` | `""` | no |
121121
| <a name="input_ram_tags"></a> [ram\_tags](#input\_ram\_tags) | Additional tags for the RAM | `map(string)` | `{}` | no |
122+
| <a name="input_region"></a> [region](#input\_region) | Region where the resource(s) will be managed. Defaults to the region set in the provider configuration | `string` | `null` | no |
122123
| <a name="input_share_tgw"></a> [share\_tgw](#input\_share\_tgw) | Whether to share your transit gateway with other accounts | `bool` | `true` | no |
123124
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
124125
| <a name="input_tgw_default_route_table_tags"></a> [tgw\_default\_route\_table\_tags](#input\_tgw\_default\_route\_table\_tags) | Additional tags for the Default TGW route table | `map(string)` | `{}` | no |

examples/multi-region/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Complete AWS Transit Gateway example
2+
3+
Configuration in this directory creates two AWS Transit Gateways in different regions.
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+
17+
<!-- BEGIN_TF_DOCS -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.4 |
24+
25+
## Providers
26+
27+
No providers.
28+
29+
## Modules
30+
31+
| Name | Source | Version |
32+
|------|--------|---------|
33+
| <a name="module_tgw"></a> [tgw](#module\_tgw) | ../../ | n/a |
34+
| <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 | ~> 5.0 |
36+
| <a name="module_vpc2"></a> [vpc2](#module\_vpc2) | terraform-aws-modules/vpc/aws | ~> 5.0 |
37+
38+
## Resources
39+
40+
No resources.
41+
42+
## Inputs
43+
44+
No inputs.
45+
46+
## Outputs
47+
48+
| Name | Description |
49+
|------|-------------|
50+
| <a name="output_ec2_transit_gateway_arn"></a> [ec2\_transit\_gateway\_arn](#output\_ec2\_transit\_gateway\_arn) | EC2 Transit Gateway Amazon Resource Name (ARN) |
51+
| <a name="output_ec2_transit_gateway_association_default_route_table_id"></a> [ec2\_transit\_gateway\_association\_default\_route\_table\_id](#output\_ec2\_transit\_gateway\_association\_default\_route\_table\_id) | Identifier of the default association route table |
52+
| <a name="output_ec2_transit_gateway_id"></a> [ec2\_transit\_gateway\_id](#output\_ec2\_transit\_gateway\_id) | EC2 Transit Gateway identifier |
53+
| <a name="output_ec2_transit_gateway_owner_id"></a> [ec2\_transit\_gateway\_owner\_id](#output\_ec2\_transit\_gateway\_owner\_id) | Identifier of the AWS account that owns the EC2 Transit Gateway |
54+
| <a name="output_ec2_transit_gateway_propagation_default_route_table_id"></a> [ec2\_transit\_gateway\_propagation\_default\_route\_table\_id](#output\_ec2\_transit\_gateway\_propagation\_default\_route\_table\_id) | Identifier of the default propagation route table |
55+
| <a name="output_ec2_transit_gateway_route_ids"></a> [ec2\_transit\_gateway\_route\_ids](#output\_ec2\_transit\_gateway\_route\_ids) | List of EC2 Transit Gateway Route Table identifier combined with destination |
56+
| <a name="output_ec2_transit_gateway_route_table_association"></a> [ec2\_transit\_gateway\_route\_table\_association](#output\_ec2\_transit\_gateway\_route\_table\_association) | Map of EC2 Transit Gateway Route Table Association attributes |
57+
| <a name="output_ec2_transit_gateway_route_table_association_ids"></a> [ec2\_transit\_gateway\_route\_table\_association\_ids](#output\_ec2\_transit\_gateway\_route\_table\_association\_ids) | List of EC2 Transit Gateway Route Table Association identifiers |
58+
| <a name="output_ec2_transit_gateway_route_table_default_association_route_table"></a> [ec2\_transit\_gateway\_route\_table\_default\_association\_route\_table](#output\_ec2\_transit\_gateway\_route\_table\_default\_association\_route\_table) | Boolean whether this is the default association route table for the EC2 Transit Gateway |
59+
| <a name="output_ec2_transit_gateway_route_table_default_propagation_route_table"></a> [ec2\_transit\_gateway\_route\_table\_default\_propagation\_route\_table](#output\_ec2\_transit\_gateway\_route\_table\_default\_propagation\_route\_table) | Boolean whether this is the default propagation route table for the EC2 Transit Gateway |
60+
| <a name="output_ec2_transit_gateway_route_table_id"></a> [ec2\_transit\_gateway\_route\_table\_id](#output\_ec2\_transit\_gateway\_route\_table\_id) | EC2 Transit Gateway Route Table identifier |
61+
| <a name="output_ec2_transit_gateway_route_table_propagation"></a> [ec2\_transit\_gateway\_route\_table\_propagation](#output\_ec2\_transit\_gateway\_route\_table\_propagation) | Map of EC2 Transit Gateway Route Table Propagation attributes |
62+
| <a name="output_ec2_transit_gateway_route_table_propagation_ids"></a> [ec2\_transit\_gateway\_route\_table\_propagation\_ids](#output\_ec2\_transit\_gateway\_route\_table\_propagation\_ids) | List of EC2 Transit Gateway Route Table Propagation identifiers |
63+
| <a name="output_ec2_transit_gateway_vpc_attachment"></a> [ec2\_transit\_gateway\_vpc\_attachment](#output\_ec2\_transit\_gateway\_vpc\_attachment) | Map of EC2 Transit Gateway VPC Attachment attributes |
64+
| <a name="output_ec2_transit_gateway_vpc_attachment_ids"></a> [ec2\_transit\_gateway\_vpc\_attachment\_ids](#output\_ec2\_transit\_gateway\_vpc\_attachment\_ids) | List of EC2 Transit Gateway VPC Attachment identifiers |
65+
| <a name="output_ram_principal_association_id"></a> [ram\_principal\_association\_id](#output\_ram\_principal\_association\_id) | The Amazon Resource Name (ARN) of the Resource Share and the principal, separated by a comma |
66+
| <a name="output_ram_resource_share_id"></a> [ram\_resource\_share\_id](#output\_ram\_resource\_share\_id) | The Amazon Resource Name (ARN) of the resource share |
67+
<!-- END_TF_DOCS -->

examples/multi-region/main.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
provider "aws" {
2+
region = local.region1
3+
}
4+
5+
locals {
6+
name = "ex-tgw-${replace(basename(path.cwd), "_", "-")}"
7+
region1 = "eu-west-1"
8+
region2 = "eu-north-1"
9+
10+
tags = {
11+
Example = local.name
12+
GithubRepo = "terraform-aws-eks"
13+
GithubOrg = "terraform-aws-transit-gateway"
14+
}
15+
}
16+
17+
################################################################################
18+
# Transit Gateway Module
19+
################################################################################
20+
21+
module "tgw_region1" {
22+
source = "../../"
23+
24+
region = local.region1
25+
26+
name = local.name
27+
description = "My TGW in ${local.region1}"
28+
amazon_side_asn = 64532
29+
30+
share_tgw = false
31+
32+
tags = local.tags
33+
}
34+
35+
module "tgw_region2" {
36+
source = "../../"
37+
38+
region = local.region2
39+
40+
name = "${local.name}-peer"
41+
description = "My TGW in ${local.region2}"
42+
amazon_side_asn = 64532
43+
44+
share_tgw = false
45+
46+
tags = local.tags
47+
}

examples/multi-region/outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

examples/multi-region/variables.tf

Whitespace-only changes.

examples/multi-region/versions.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 4.4"
8+
}
9+
}
10+
}

main.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ locals {
2828
resource "aws_ec2_transit_gateway" "this" {
2929
count = var.create_tgw ? 1 : 0
3030

31+
region = var.region
32+
3133
description = coalesce(var.description, var.name)
3234
amazon_side_asn = var.amazon_side_asn
3335
default_route_table_association = var.enable_default_route_table_association ? "enable" : "disable"
@@ -55,6 +57,8 @@ resource "aws_ec2_transit_gateway" "this" {
5557
resource "aws_ec2_tag" "this" {
5658
for_each = { for k, v in local.tgw_default_route_table_tags_merged : k => v if var.create_tgw && var.enable_default_route_table_association }
5759

60+
region = var.region
61+
5862
resource_id = aws_ec2_transit_gateway.this[0].association_default_route_table_id
5963
key = each.key
6064
value = each.value
@@ -67,6 +71,8 @@ resource "aws_ec2_tag" "this" {
6771
resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
6872
for_each = var.vpc_attachments
6973

74+
region = var.region
75+
7076
transit_gateway_id = var.create_tgw ? aws_ec2_transit_gateway.this[0].id : each.value.tgw_id
7177
vpc_id = each.value.vpc_id
7278
subnet_ids = each.value.subnet_ids
@@ -93,6 +99,8 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
9399
resource "aws_ec2_transit_gateway_route_table" "this" {
94100
count = var.create_tgw && var.create_tgw_routes ? 1 : 0
95101

102+
region = var.region
103+
96104
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
97105

98106
tags = merge(
@@ -105,6 +113,8 @@ resource "aws_ec2_transit_gateway_route_table" "this" {
105113
resource "aws_ec2_transit_gateway_route" "this" {
106114
count = var.create_tgw_routes ? length(local.vpc_attachments_with_routes) : 0
107115

116+
region = var.region
117+
108118
destination_cidr_block = local.vpc_attachments_with_routes[count.index][1].destination_cidr_block
109119
blackhole = try(local.vpc_attachments_with_routes[count.index][1].blackhole, null)
110120

@@ -118,6 +128,8 @@ resource "aws_route" "this" {
118128
tgw_id = x.tgw_id
119129
} }
120130

131+
region = var.region
132+
121133
route_table_id = each.key
122134
destination_cidr_block = try(each.value.ipv6_support, false) ? null : each.value["cidr"]
123135
destination_ipv6_cidr_block = try(each.value.ipv6_support, false) ? each.value["cidr"] : null
@@ -129,6 +141,8 @@ resource "aws_ec2_transit_gateway_route_table_association" "this" {
129141
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
130142
}
131143

144+
region = var.region
145+
132146
# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
133147
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.this[each.key].id
134148
transit_gateway_route_table_id = var.create_tgw ? aws_ec2_transit_gateway_route_table.this[0].id : try(each.value.transit_gateway_route_table_id, var.transit_gateway_route_table_id)
@@ -139,6 +153,8 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
139153
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
140154
}
141155

156+
region = var.region
157+
142158
# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
143159
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.this[each.key].id
144160
transit_gateway_route_table_id = var.create_tgw ? aws_ec2_transit_gateway_route_table.this[0].id : try(each.value.transit_gateway_route_table_id, var.transit_gateway_route_table_id)
@@ -151,6 +167,8 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
151167
resource "aws_ram_resource_share" "this" {
152168
count = var.create_tgw && var.share_tgw ? 1 : 0
153169

170+
region = var.region
171+
154172
name = coalesce(var.ram_name, var.name)
155173
allow_external_principals = var.ram_allow_external_principals
156174

@@ -164,19 +182,25 @@ resource "aws_ram_resource_share" "this" {
164182
resource "aws_ram_resource_association" "this" {
165183
count = var.create_tgw && var.share_tgw ? 1 : 0
166184

185+
region = var.region
186+
167187
resource_arn = aws_ec2_transit_gateway.this[0].arn
168188
resource_share_arn = aws_ram_resource_share.this[0].id
169189
}
170190

171191
resource "aws_ram_principal_association" "this" {
172192
count = var.create_tgw && var.share_tgw ? length(var.ram_principals) : 0
173193

194+
region = var.region
195+
174196
principal = var.ram_principals[count.index]
175197
resource_share_arn = aws_ram_resource_share.this[0].arn
176198
}
177199

178200
resource "aws_ram_resource_share_accepter" "this" {
179201
count = !var.create_tgw && var.share_tgw ? 1 : 0
180202

203+
region = var.region
204+
181205
share_arn = var.ram_resource_share_arn
182206
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ variable "tags" {
1010
default = {}
1111
}
1212

13+
variable "region" {
14+
description = "Region where the resource(s) will be managed. Defaults to the region set in the provider configuration"
15+
type = string
16+
default = null
17+
}
18+
1319
################################################################################
1420
# Transit Gateway
1521
################################################################################

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.4"
7+
version = ">= 6.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)