Skip to content

Commit 3b70cc0

Browse files
committed
chore: update to align with current standards
1 parent 6488672 commit 3b70cc0

File tree

9 files changed

+337
-243
lines changed

9 files changed

+337
-243
lines changed

examples/complete/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ Note that this example may create resources which cost money. Run `terraform des
4646

4747
| Name | Type |
4848
|------|------|
49-
| [aws_subnet_ids.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
50-
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
49+
| [aws_subnet_ids.vpc1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
50+
| [aws_subnet_ids.vpc2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
51+
| [aws_vpc.vpc1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
52+
| [aws_vpc.vpc2](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
5153

5254
## Inputs
5355

examples/complete/main.tf

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
provider "aws" {
2-
region = "eu-west-1"
2+
region = local.region
33
}
44

5-
# See Notes in README.md for explanation regarding using data-sources and computed values
6-
data "aws_vpc" "default" {
7-
default = true
8-
}
5+
locals {
6+
name = "ex-tgw-${replace(basename(path.cwd), "_", "-")}"
7+
region = "eu-west-1"
98

10-
data "aws_subnet_ids" "this" {
11-
vpc_id = data.aws_vpc.default.id
9+
tags = {
10+
Example = local.name
11+
GithubRepo = "terraform-aws-eks"
12+
GithubOrg = "terraform-aws-transit-gateway"
13+
}
1214
}
1315

16+
################################################################################
17+
# Transit Gateway Module
18+
################################################################################
19+
1420
module "tgw" {
1521
source = "../../"
1622

17-
name = "my-tgw"
23+
name = local.name
1824
description = "My TGW shared with several other AWS accounts"
1925
amazon_side_asn = 64532
2026

2127
enable_auto_accept_shared_attachments = true # When "true" there is no need for RAM resources if using multiple AWS accounts
2228

2329
vpc_attachments = {
2430
vpc1 = {
25-
vpc_id = data.aws_vpc.default.id # module.vpc1.vpc_id
26-
subnet_ids = data.aws_subnet_ids.this.ids # module.vpc1.private_subnets
27-
dns_support = true
28-
ipv6_support = true
31+
vpc_id = data.aws_vpc.vpc1.id # module.vpc1.vpc_id
32+
subnet_ids = data.aws_subnets.vpc1.ids # module.vpc1.private_subnets
33+
dns_support = true
34+
ipv6_support = true
35+
2936
transit_gateway_default_route_table_association = false
3037
transit_gateway_default_route_table_propagation = false
31-
# transit_gateway_route_table_id = "tgw-rtb-073a181ee589b360f"
38+
# transit_gateway_route_table_id = "tgw-rtb-073a181ee589b360f"
3239

3340
tgw_routes = [
3441
{
@@ -41,8 +48,8 @@ module "tgw" {
4148
]
4249
},
4350
vpc2 = {
44-
vpc_id = data.aws_vpc.default.id # module.vpc2.vpc_id
45-
subnet_ids = data.aws_subnet_ids.this.ids # module.vpc2.private_subnets
51+
vpc_id = data.aws_vpc.vpc2.id # module.vpc2.vpc_id
52+
subnet_ids = data.aws_subnets.vpc2.ids # module.vpc2.private_subnets
4653

4754
tgw_routes = [
4855
{
@@ -59,37 +66,65 @@ module "tgw" {
5966
ram_allow_external_principals = true
6067
ram_principals = [307990089504]
6168

62-
tags = {
63-
Purpose = "tgw-complete-example"
64-
}
69+
tags = local.tags
6570
}
6671

72+
################################################################################
73+
# Supporting resources
74+
################################################################################
75+
6776
module "vpc1" {
6877
source = "terraform-aws-modules/vpc/aws"
6978
version = "~> 3.0"
7079

71-
name = "vpc1"
72-
80+
name = "${local.name}-vpc1"
7381
cidr = "10.10.0.0/16"
7482

75-
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
83+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
7684
private_subnets = ["10.10.1.0/24", "10.10.2.0/24", "10.10.3.0/24"]
7785

7886
enable_ipv6 = true
7987
private_subnet_assign_ipv6_address_on_creation = true
8088
private_subnet_ipv6_prefixes = [0, 1, 2]
89+
90+
tags = local.tags
91+
}
92+
93+
# See Notes in README.md for explanation regarding using data-sources and computed values
94+
data "aws_vpc" "vpc1" {
95+
id = module.vpc1.vpc_id
96+
}
97+
98+
data "aws_subnets" "vpc1" {
99+
filter {
100+
name = "vpc-id"
101+
values = [module.vpc1.vpc_id]
102+
}
81103
}
82104

83105
module "vpc2" {
84106
source = "terraform-aws-modules/vpc/aws"
85107
version = "~> 3.0"
86108

87-
name = "vpc2"
88-
109+
name = "${local.name}-vpc2"
89110
cidr = "10.20.0.0/16"
90111

91-
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
112+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
92113
private_subnets = ["10.20.1.0/24", "10.20.2.0/24", "10.20.3.0/24"]
93114

94115
enable_ipv6 = false
116+
117+
tags = local.tags
118+
}
119+
120+
# See Notes in README.md for explanation regarding using data-sources and computed values
121+
data "aws_vpc" "vpc2" {
122+
id = module.vpc2.vpc_id
123+
}
124+
125+
data "aws_subnets" "vpc2" {
126+
filter {
127+
name = "vpc-id"
128+
values = [module.vpc2.vpc_id]
129+
}
95130
}

examples/complete/outputs.tf

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# aws_ec2_transit_gateway
1+
################################################################################
2+
# Transit Gateway
3+
################################################################################
4+
25
output "ec2_transit_gateway_arn" {
36
description = "EC2 Transit Gateway Amazon Resource Name (ARN)"
47
value = module.tgw.ec2_transit_gateway_arn
58
}
69

7-
output "ec2_transit_gateway_association_default_route_table_id" {
8-
description = "Identifier of the default association route table"
9-
value = module.tgw.ec2_transit_gateway_association_default_route_table_id
10-
}
11-
1210
output "ec2_transit_gateway_id" {
1311
description = "EC2 Transit Gateway identifier"
1412
value = module.tgw.ec2_transit_gateway_id
@@ -19,45 +17,54 @@ output "ec2_transit_gateway_owner_id" {
1917
value = module.tgw.ec2_transit_gateway_owner_id
2018
}
2119

20+
output "ec2_transit_gateway_association_default_route_table_id" {
21+
description = "Identifier of the default association route table"
22+
value = module.tgw.ec2_transit_gateway_association_default_route_table_id
23+
}
24+
2225
output "ec2_transit_gateway_propagation_default_route_table_id" {
2326
description = "Identifier of the default propagation route table"
2427
value = module.tgw.ec2_transit_gateway_propagation_default_route_table_id
2528
}
2629

27-
output "ec2_transit_gateway_route_table_default_association_route_table" {
28-
description = "Boolean whether this is the default association route table for the EC2 Transit Gateway"
29-
value = module.tgw.ec2_transit_gateway_route_table_default_association_route_table
30+
################################################################################
31+
# VPC Attachment
32+
################################################################################
33+
34+
output "ec2_transit_gateway_vpc_attachment_ids" {
35+
description = "List of EC2 Transit Gateway VPC Attachment identifiers"
36+
value = module.tgw.ec2_transit_gateway_vpc_attachment_ids
3037
}
3138

32-
output "ec2_transit_gateway_route_table_default_propagation_route_table" {
33-
description = "Boolean whether this is the default propagation route table for the EC2 Transit Gateway"
34-
value = module.tgw.ec2_transit_gateway_route_table_default_propagation_route_table
39+
output "ec2_transit_gateway_vpc_attachment" {
40+
description = "Map of EC2 Transit Gateway VPC Attachment attributes"
41+
value = module.tgw.ec2_transit_gateway_vpc_attachment
3542
}
3643

37-
# aws_ec2_transit_gateway_route_table
44+
################################################################################
45+
# Route Table / Routes
46+
################################################################################
47+
3848
output "ec2_transit_gateway_route_table_id" {
3949
description = "EC2 Transit Gateway Route Table identifier"
4050
value = module.tgw.ec2_transit_gateway_route_table_id
4151
}
4252

43-
# aws_ec2_transit_gateway_route
44-
output "ec2_transit_gateway_route_ids" {
45-
description = "List of EC2 Transit Gateway Route Table identifier combined with destination"
46-
value = module.tgw.ec2_transit_gateway_route_ids
53+
output "ec2_transit_gateway_route_table_default_association_route_table" {
54+
description = "Boolean whether this is the default association route table for the EC2 Transit Gateway"
55+
value = module.tgw.ec2_transit_gateway_route_table_default_association_route_table
4756
}
4857

49-
# aws_ec2_transit_gateway_vpc_attachment
50-
output "ec2_transit_gateway_vpc_attachment_ids" {
51-
description = "List of EC2 Transit Gateway VPC Attachment identifiers"
52-
value = module.tgw.ec2_transit_gateway_vpc_attachment_ids
58+
output "ec2_transit_gateway_route_table_default_propagation_route_table" {
59+
description = "Boolean whether this is the default propagation route table for the EC2 Transit Gateway"
60+
value = module.tgw.ec2_transit_gateway_route_table_default_propagation_route_table
5361
}
5462

55-
output "ec2_transit_gateway_vpc_attachment" {
56-
description = "Map of EC2 Transit Gateway VPC Attachment attributes"
57-
value = module.tgw.ec2_transit_gateway_vpc_attachment
63+
output "ec2_transit_gateway_route_ids" {
64+
description = "List of EC2 Transit Gateway Route Table identifier combined with destination"
65+
value = module.tgw.ec2_transit_gateway_route_ids
5866
}
5967

60-
# aws_ec2_transit_gateway_route_table_association
6168
output "ec2_transit_gateway_route_table_association_ids" {
6269
description = "List of EC2 Transit Gateway Route Table Association identifiers"
6370
value = module.tgw.ec2_transit_gateway_route_table_association_ids
@@ -68,7 +75,6 @@ output "ec2_transit_gateway_route_table_association" {
6875
value = module.tgw.ec2_transit_gateway_route_table_association
6976
}
7077

71-
# aws_ec2_transit_gateway_route_table_propagation
7278
output "ec2_transit_gateway_route_table_propagation_ids" {
7379
description = "List of EC2 Transit Gateway Route Table Propagation identifiers"
7480
value = module.tgw.ec2_transit_gateway_route_table_propagation_ids
@@ -79,13 +85,15 @@ output "ec2_transit_gateway_route_table_propagation" {
7985
value = module.tgw.ec2_transit_gateway_route_table_propagation
8086
}
8187

82-
# aws_ram_resource_share
88+
################################################################################
89+
# Resource Access Manager
90+
################################################################################
91+
8392
output "ram_resource_share_id" {
8493
description = "The Amazon Resource Name (ARN) of the resource share"
8594
value = module.tgw.ram_resource_share_id
8695
}
8796

88-
# aws_ram_principal_association
8997
output "ram_principal_association_id" {
9098
description = "The Amazon Resource Name (ARN) of the Resource Share and the principal, separated by a comma"
9199
value = module.tgw.ram_principal_association_id

examples/multi-account/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Note that this example may create resources which cost money. Run `terraform des
4646

4747
| Name | Type |
4848
|------|------|
49-
| [aws_subnet_ids.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
50-
| [aws_vpc.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
49+
| [aws_subnet_ids.vpc1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet_ids) | data source |
50+
| [aws_vpc.vpc1](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
5151

5252
## Inputs
5353

0 commit comments

Comments
 (0)