generated from cloudposse-terraform-components/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.yaml
282 lines (241 loc) · 9.27 KB
/
README.yaml
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: "aws-tgw-hub"
# Canonical GitHub repo
github_repo: "cloudposse-terraform-components/aws-tgw-hub"
# Short description of this project
description: |-
This component is responsible for provisioning an [AWS Transit Gateway](https://aws.amazon.com/transit-gateway) `hub`
that acts as a centralized gateway for connecting VPCs from other `spoke` accounts.
usage: |-
**Stack Level**: Regional
## Basic Usage with `tgw/spoke`
Here's an example snippet for how to configure and use this component:
```yaml
components:
terraform:
tgw/hub/defaults:
metadata:
type: abstract
component: tgw/hub
vars:
enabled: true
name: tgw-hub
expose_eks_sg: false
tags:
Team: sre
Service: tgw-hub
tgw/hub:
metadata:
inherits:
- tgw/hub/defaults
component: tgw/hub
vars:
connections:
- account:
tenant: core
stage: network
vpc_component_names:
- vpc-dev
- account:
tenant: core
stage: artifacts
- account:
tenant: core
stage: auto
eks_component_names:
- eks/cluster
- account:
tenant: plat
stage: dev
vpc_component_names:
- vpc
- vpc/data/1
eks_component_names:
- eks/cluster
- account:
tenant: plat
stage: staging
vpc_component_names:
- vpc
- vpc/data/1
eks_component_names:
- eks/cluster
- account:
tenant: plat
stage: prod
vpc_component_names:
- vpc
- vpc/data/1
eks_component_names:
- eks/cluster
```
To provision the Transit Gateway and all related resources, run the following commands:
```sh
atmos terraform plan tgw/hub -s <tenant>-<environment>-network
atmos terraform apply tgw/hub -s <tenant>-<environment>-network
```
## Alternate Usage with `tgw/attachment`, `tgw/routes`, and `vpc/routes`
### Components Overview
- **`tgw/hub`**: Creates the Transit Gateway in the network account
- **`tgw/attachment`**: Creates and manages Transit Gateway VPC attachments in connected accounts
- **`tgw/hub-connection`**: Creates the Transit Gateway peering connection between two `tgw/hub` deployments
- **`tgw/routes`**: Manages Transit Gateway route tables in the network account
- **`vpc-routes`** (`vpc/routes/private`): Configures VPC route tables in connected accounts to route traffic through the Transit Gateway (Note: This component lives outside the `tgw/` directory since it's not specific to Transit Gateway)
### Architecture
The Transit Gateway components work together in the following way:
1. Transit Gateway is created in the network account (`tgw/hub`)
2. VPCs in other accounts attach to the Transit Gateway (`tgw/attachment`)
3. Route tables in connected VPCs direct traffic across accounts (`vpc-routes`)
4. Transit Gateway route tables control routing between attachments (`tgw/routes`)
```mermaid
graph TD
subgraph core-use1-network
TGW[Transit Gateway]
TGW_RT[TGW Route Tables]
end
subgraph plat-use1-dev
VPC1[VPC]
VPC1_RT[VPC Route Tables]
ATT1[TGW Attachment]
end
subgraph core-use1-auto
VPC2[VPC]
VPC2_RT[VPC Route Tables]
ATT2[TGW Attachment]
end
ATT1 <--> TGW
ATT2 <--> TGW
TGW <--> TGW_RT
VPC1_RT <--> VPC1
VPC2_RT <--> VPC2
VPC1 <--> ATT1
VPC2 <--> ATT2
```
### Deployment Steps
#### 1. Deploy Transit Gateway Hub
First, create the Transit Gateway in the network account.
> [!TIP]
> Leave `var.connections` empty. With this refactor, the `tgw/hub` component is only responsible for creating the Transit Gateway and its route tables. We do not need to fetch and store outputs for the connected components anymore.
```yaml
components:
terraform:
tgw/hub:
vars:
connections: []
```
#### 2. Deploy VPC Attachments
Important: Deploy attachments in connected accounts first, before deploying attachments in the network account.
##### Connected Account Attachments
```yaml
components:
terraform:
tgw/attachment:
vars:
transit_gateway_id: !terraform.output tgw/hub core-use1-network transit_gateway_id
transit_gateway_route_table_id: !terraform.output tgw/hub core-use1-network transit_gateway_route_table_id
create_transit_gateway_route_table_association: false
```
##### Network Account Attachment
```yaml
components:
terraform:
tgw/attachment:
vars:
transit_gateway_id: !terraform.output tgw/hub core-use1-network transit_gateway_id
transit_gateway_route_table_id: !terraform.output tgw/hub core-use1-network transit_gateway_route_table_id
# Route table associations are required so that route tables can propagate their routes to other route tables.
# Set the following to true in the same account where the Transit Gateway and its route tables are deployed
create_transit_gateway_route_table_association: true
# Associate connected accounts with the Transit Gateway route table
additional_associations:
- attachment_id: !terraform.output tgw/attachment core-use1-auto transit_gateway_vpc_attachment_id
route_table_id: !terraform.output tgw/hub transit_gateway_route_table_id
- attachment_id: !terraform.output tgw/attachment plat-use1-dev transit_gateway_vpc_attachment_id
route_table_id: !terraform.output tgw/hub transit_gateway_route_table_id
```
#### 3. Configure VPC Routes
Configure routes in all connected VPCs.
```yaml
components:
terraform:
vpc/routes/private:
metadata:
component: vpc-routes
vars:
route_table_ids: !terraform.output vpc private_route_table_ids
routes:
# Route to network account
- destination:
cidr_block: !terraform.output vpc core-use1-network vpc_cidr
target:
type: transit_gateway_id
value: !terraform.output tgw/hub core-use1-network transit_gateway_id
# Route to core-auto account, if necessary
- destination:
cidr_block: !terraform.output vpc core-use1-auto vpc_cidr
target:
type: transit_gateway_id
value: !terraform.output tgw/hub core-use1-network transit_gateway_id
```
Configure routes in the Network Account VPCs.
```yaml
components:
terraform:
vpc/routes/private:
vars:
route_table_ids: !terraform.output vpc private_route_table_ids
routes:
# Routes to connected accounts
- destination:
cidr_block: !terraform.output vpc core-use1-auto vpc_cidr
target:
type: transit_gateway_id
value: !terraform.output tgw/hub transit_gateway_id
- destination:
cidr_block: !terraform.output vpc plat-use1-dev vpc_cidr
target:
type: transit_gateway_id
value: !terraform.output tgw/hub transit_gateway_id
```
### 4. Deploy Transit Gateway Route Table Routes
Deploy the `tgw/routes` component in the network account to create route tables and routes.
```yaml
components:
terraform:
tgw/routes:
vars:
transit_gateway_route_table_id: !terraform.output tgw/hub transit_gateway_route_table_id
# Use propagated routes to route through VPC attachments
propagated_routes:
# Route to this account
- attachment_id: !terraform.output tgw/attachment core-use1-network transit_gateway_attachment_id
# Route to any connected account
- attachment_id: !terraform.output tgw/attachment core-use1-auto transit_gateway_attachment_id
- attachment_id: !terraform.output tgw/attachment plat-use1-dev transit_gateway_attachment_id
```
tags:
- component/tgw/hub
- layer/network
- provider/aws
# Categories of this project
categories:
- component/tgw/hub
- layer/network
- provider/aws
# License of this project
license: "APACHE2"
# Badges to display
badges:
- name: Latest Release
image: https://img.shields.io/github/release/cloudposse-terraform-components/aws-tgw-hub.svg?style=for-the-badge
url: https://github.com/cloudposse-terraform-components/aws-tgw-hub/releases/latest
- name: Slack Community
image: https://slack.cloudposse.com/for-the-badge.svg
url: https://slack.cloudposse.com
related:
- name: "Cloud Posse Terraform Modules"
description: Our collection of reusable Terraform modules used by our reference architectures.
url: "https://docs.cloudposse.com/modules/"
- name: "Atmos"
description: "Atmos is like docker-compose but for your infrastructure"
url: "https://atmos.tools"
contributors: [] # If included generates contribs