forked from cloudposse/terraform-aws-transit-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
175 lines (149 loc) · 6.89 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Create the Transit Gateway, route table associations/propagations, and static TGW routes in the `network` account.
# Enable sharing the Transit Gateway with the Organization using Resource Access Manager (RAM).
# If you would like to share resources with your organization or organizational units,
# then you must use the AWS RAM console or CLI command to enable sharing with AWS Organizations.
# When you share resources within your organization,
# AWS RAM does not send invitations to principals. Principals in your organization get access to shared resources without exchanging invitations.
# https://docs.aws.amazon.com/ram/latest/userguide/getting-started-sharing.html
module "transit_gateway" {
source = "../../"
ram_resource_share_enabled = true
create_transit_gateway = true
create_transit_gateway_route_table = true
create_transit_gateway_vpc_attachment = false
create_transit_gateway_route_table_association_and_propagation = true
config = {
prod = {
vpc_id = null
vpc_cidr = null
subnet_ids = null
subnet_route_table_ids = null
route_to = null
route_to_cidr_blocks = null
transit_gateway_vpc_attachment_id = module.transit_gateway_vpc_attachments_and_subnet_routes_prod.transit_gateway_vpc_attachment_ids["prod"]
static_routes = [
{
blackhole = true
destination_cidr_block = "0.0.0.0/0"
},
{
blackhole = false
destination_cidr_block = "172.16.1.0/24"
}
]
},
staging = {
vpc_id = null
vpc_cidr = null
subnet_ids = null
subnet_route_table_ids = null
route_to = null
route_to_cidr_blocks = null
transit_gateway_vpc_attachment_id = module.transit_gateway_vpc_attachments_and_subnet_routes_staging.transit_gateway_vpc_attachment_ids["staging"]
static_routes = [
{
blackhole = false
destination_cidr_block = "172.32.1.0/24"
}
]
},
dev = {
vpc_id = null
vpc_cidr = null
subnet_ids = null
subnet_route_table_ids = null
route_to = null
route_to_cidr_blocks = null
static_routes = null
transit_gateway_vpc_attachment_id = module.transit_gateway_vpc_attachments_and_subnet_routes_dev.transit_gateway_vpc_attachment_ids["dev"]
}
}
context = module.this.context
providers = {
aws = aws.network
}
}
# Create the Transit Gateway VPC attachments and subnets routes in the `prod`, `staging` and `dev` accounts
module "transit_gateway_vpc_attachments_and_subnet_routes_prod" {
source = "../../"
# `prod` account can access the Transit Gateway in the `network` account since we shared the Transit Gateway with the Organization using Resource Access Manager
existing_transit_gateway_id = module.transit_gateway.transit_gateway_id
existing_transit_gateway_route_table_id = module.transit_gateway.transit_gateway_route_table_id
create_transit_gateway = false
create_transit_gateway_route_table = false
create_transit_gateway_vpc_attachment = true
create_transit_gateway_route_table_association_and_propagation = false
config = {
prod = {
vpc_id = module.vpc_prod.vpc_id
vpc_cidr = module.vpc_prod.vpc_cidr_block
subnet_ids = module.subnets_prod.private_subnet_ids
subnet_route_table_ids = module.subnets_prod.private_route_table_ids
route_to = null
route_to_cidr_blocks = [
module.vpc_staging.vpc_cidr_block,
module.vpc_dev.vpc_cidr_block
]
static_routes = null
transit_gateway_vpc_attachment_id = null
}
}
context = module.this.context
providers = {
aws = aws.prod
}
}
module "transit_gateway_vpc_attachments_and_subnet_routes_staging" {
source = "../../"
# `staging` account can access the Transit Gateway in the `network` account since we shared the Transit Gateway with the Organization using Resource Access Manager
existing_transit_gateway_id = module.transit_gateway.transit_gateway_id
existing_transit_gateway_route_table_id = module.transit_gateway.transit_gateway_route_table_id
create_transit_gateway = false
create_transit_gateway_route_table = false
create_transit_gateway_vpc_attachment = true
create_transit_gateway_route_table_association_and_propagation = false
config = {
staging = {
vpc_id = module.vpc_staging.vpc_id
vpc_cidr = module.vpc_staging.vpc_cidr_block
subnet_ids = module.subnets_staging.private_subnet_ids
subnet_route_table_ids = module.subnets_staging.private_route_table_ids
route_to = null
route_to_cidr_blocks = [
module.vpc_dev.vpc_cidr_block
]
static_routes = null
transit_gateway_vpc_attachment_id = null
}
}
context = module.this.context
providers = {
aws = aws.staging
}
}
module "transit_gateway_vpc_attachments_and_subnet_routes_dev" {
source = "../../"
# `dev` account can access the Transit Gateway in the `network` account since we shared the Transit Gateway with the Organization using Resource Access Manager
existing_transit_gateway_id = module.transit_gateway.transit_gateway_id
existing_transit_gateway_route_table_id = module.transit_gateway.transit_gateway_route_table_id
create_transit_gateway = false
create_transit_gateway_route_table = false
create_transit_gateway_vpc_attachment = true
create_transit_gateway_route_table_association_and_propagation = false
config = {
dev = {
vpc_id = module.vpc_dev.vpc_id
vpc_cidr = module.vpc_dev.vpc_cidr_block
subnet_ids = module.subnets_dev.private_subnet_ids
subnet_route_table_ids = module.subnets_dev.private_route_table_ids
route_to = null
route_to_cidr_blocks = null
static_routes = null
transit_gateway_vpc_attachment_id = null
}
}
context = module.this.context
providers = {
aws = aws.dev
}
}