Skip to content

Commit f47f7e9

Browse files
Gert van den Bergbryantbiggs
authored andcommitted
Add support for specifying the region for version 6+ of the AWS provider
1 parent b0e2730 commit f47f7e9

File tree

9 files changed

+159
-3
lines changed

9 files changed

+159
-3
lines changed

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
@@ -95,6 +101,8 @@ resource "aws_ec2_transit_gateway_vpc_attachment" "this" {
95101
resource "aws_ec2_transit_gateway_route_table" "this" {
96102
count = var.create_tgw && var.create_tgw_routes ? 1 : 0
97103

104+
region = var.region
105+
98106
transit_gateway_id = aws_ec2_transit_gateway.this[0].id
99107

100108
tags = merge(
@@ -107,6 +115,8 @@ resource "aws_ec2_transit_gateway_route_table" "this" {
107115
resource "aws_ec2_transit_gateway_route" "this" {
108116
count = var.create_tgw_routes ? length(local.vpc_attachments_with_routes) : 0
109117

118+
region = var.region
119+
110120
destination_cidr_block = local.vpc_attachments_with_routes[count.index][1].destination_cidr_block
111121
blackhole = try(local.vpc_attachments_with_routes[count.index][1].blackhole, null)
112122

@@ -120,6 +130,8 @@ resource "aws_route" "this" {
120130
tgw_id = x.tgw_id
121131
} }
122132

133+
region = var.region
134+
123135
route_table_id = each.key
124136
destination_cidr_block = try(each.value.ipv6_support, false) ? null : each.value["cidr"]
125137
destination_ipv6_cidr_block = try(each.value.ipv6_support, false) ? each.value["cidr"] : null
@@ -133,6 +145,8 @@ resource "aws_ec2_transit_gateway_route_table_association" "this" {
133145
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
134146
}
135147

148+
region = var.region
149+
136150
# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
137151
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.this[each.key].id
138152
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)
@@ -143,6 +157,8 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
143157
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
144158
}
145159

160+
region = var.region
161+
146162
# Create association if it was not set already by aws_ec2_transit_gateway_vpc_attachment resource
147163
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.this[each.key].id
148164
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)
@@ -155,6 +171,8 @@ resource "aws_ec2_transit_gateway_route_table_propagation" "this" {
155171
resource "aws_ram_resource_share" "this" {
156172
count = var.create_tgw && var.share_tgw ? 1 : 0
157173

174+
region = var.region
175+
158176
name = coalesce(var.ram_name, var.name)
159177
allow_external_principals = var.ram_allow_external_principals
160178

@@ -168,19 +186,25 @@ resource "aws_ram_resource_share" "this" {
168186
resource "aws_ram_resource_association" "this" {
169187
count = var.create_tgw && var.share_tgw ? 1 : 0
170188

189+
region = var.region
190+
171191
resource_arn = aws_ec2_transit_gateway.this[0].arn
172192
resource_share_arn = aws_ram_resource_share.this[0].id
173193
}
174194

175195
resource "aws_ram_principal_association" "this" {
176196
count = var.create_tgw && var.share_tgw ? length(var.ram_principals) : 0
177197

198+
region = var.region
199+
178200
principal = var.ram_principals[count.index]
179201
resource_share_arn = aws_ram_resource_share.this[0].arn
180202
}
181203

182204
resource "aws_ram_resource_share_accepter" "this" {
183205
count = !var.create_tgw && var.share_tgw ? 1 : 0
184206

207+
region = var.region
208+
185209
share_arn = var.ram_resource_share_arn
186210
}

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)