-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME.yaml
More file actions
289 lines (247 loc) · 9.19 KB
/
Copy pathREADME.yaml
File metadata and controls
289 lines (247 loc) · 9.19 KB
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
283
284
285
286
287
288
289
name: "aws-vpc"
# Canonical GitHub repo
github_repo: "cloudposse-terraform-components/aws-vpc"
# Short description of this project
description: |-
This component is responsible for provisioning a VPC and corresponding Subnets with advanced configuration capabilities.
**Key Features:**
- Independent control over public and private subnet counts per Availability Zone
- Flexible NAT Gateway placement (index-based or name-based)
- Named subnets with different naming schemes for public vs private
- Cost optimization through strategic NAT Gateway placement
- VPC Flow Logs support for auditing and compliance
- VPC Endpoints for AWS services (S3, DynamoDB, and interface endpoints)
- AWS Shield Advanced protection for NAT Gateway EIPs (optional)
**What's New in v3.1.0:**
- Uses `terraform-aws-dynamic-subnets` v3.1.0 with enhanced subnet configuration
- Separate public/private subnet counts and names per AZ
- Precise NAT Gateway placement control for cost optimization
- NAT Gateway IDs and private IPs exposed in subnet stats outputs
- Requires AWS Provider v5.0+
usage: |-
**Stack Level**: Regional
## Basic Configuration
Here's a basic example using legacy configuration (fully backward compatible):
```yaml
# catalog/vpc/defaults
components:
terraform:
vpc/defaults:
metadata:
type: abstract
component: vpc
settings:
spacelift:
workspace_enabled: true
vars:
enabled: true
name: vpc
availability_zones:
- "a"
- "b"
- "c"
nat_gateway_enabled: true
nat_instance_enabled: false
max_subnet_count: 3
vpc_flow_logs_enabled: true
vpc_flow_logs_bucket_environment_name: <environment>
vpc_flow_logs_bucket_stage_name: audit
vpc_flow_logs_traffic_type: "ALL"
subnet_type_tag_key: "example.net/subnet/type"
# Legacy subnet configuration (still supported)
subnets_per_az_count: 1
subnets_per_az_names: ["common"]
```
```yaml
# stacks/ue2-dev.yaml
import:
- catalog/vpc
components:
terraform:
vpc:
metadata:
component: vpc
inherits:
- vpc/defaults
vars:
ipv4_primary_cidr_block: "10.111.0.0/18"
```
## Cost-Optimized NAT Configuration
Reduce NAT Gateway costs by placing NAT Gateways in only one public subnet per AZ:
```yaml
components:
terraform:
vpc:
vars:
# Create 2 public subnets per AZ
public_subnets_per_az_count: 2
public_subnets_per_az_names: ["loadbalancer", "web"]
# Create 3 private subnets per AZ
private_subnets_per_az_count: 3
private_subnets_per_az_names: ["app", "database", "cache"]
# Place NAT Gateway ONLY in the first public subnet (index 0)
# This saves ~67% on NAT Gateway costs compared to NAT in all public subnets
nat_gateway_public_subnet_indices: [0]
```
**Cost Savings Example (3 AZs, us-east-1):**
- Without optimization: 6 NAT Gateways (2 per AZ) = ~$270/month
- With optimization: 3 NAT Gateways (1 per AZ) = ~$135/month
- **Monthly Savings: ~$135 (~$1,620/year)**
**Important**: You can use EITHER `nat_gateway_public_subnet_indices` OR `nat_gateway_public_subnet_names`, but not both. The plan will fail if both are specified.
## Named NAT Gateway Placement
Place NAT Gateways by subnet name instead of index:
```yaml
components:
terraform:
vpc:
vars:
# Must specify both count and names when using named subnets
public_subnets_per_az_count: 2
public_subnets_per_az_names: ["loadbalancer", "web"]
private_subnets_per_az_count: 2
private_subnets_per_az_names: ["app", "database"]
# Place NAT Gateway only in "loadbalancer" subnet
nat_gateway_public_subnet_names: ["loadbalancer"]
```
**Important**: When using `public_subnets_per_az_names` or `private_subnets_per_az_names`, you must also specify the corresponding count variables (`public_subnets_per_az_count` / `private_subnets_per_az_count`).
## High-Availability NAT Configuration
For production environments requiring redundancy:
```yaml
components:
terraform:
vpc:
vars:
public_subnets_per_az_count: 2
nat_gateway_public_subnet_indices: [0, 1] # NAT in both public subnets per AZ
```
## Separate Public/Private Subnet Architecture
Different subnet counts and names for public vs private:
```yaml
components:
terraform:
vpc:
vars:
# 2 public subnets per AZ for load balancers and public services
public_subnets_per_az_count: 2
public_subnets_per_az_names: ["alb", "nat"]
# 4 private subnets per AZ for different application tiers
private_subnets_per_az_count: 4
private_subnets_per_az_names: ["web", "app", "data", "cache"]
# NAT Gateway in "nat" subnet
nat_gateway_public_subnet_names: ["nat"]
```
## VPC Endpoints Configuration
Add VPC Endpoints for AWS services to reduce data transfer costs and improve security:
```yaml
components:
terraform:
vpc:
vars:
# Gateway endpoints (no hourly charges)
gateway_vpc_endpoints:
- "s3"
- "dynamodb"
# Interface endpoints (hourly charges apply)
interface_vpc_endpoints:
- "ec2"
- "ecr.api"
- "ecr.dkr"
- "logs"
- "secretsmanager"
```
## Complete Production Example
```yaml
components:
terraform:
vpc:
vars:
enabled: true
name: vpc
ipv4_primary_cidr_block: "10.0.0.0/16"
availability_zones:
- "a"
- "b"
- "c"
# Public subnets for ALB and NAT
public_subnets_per_az_count: 2
public_subnets_per_az_names: ["loadbalancer", "nat"]
# Private subnets for different tiers
private_subnets_per_az_count: 3
private_subnets_per_az_names: ["app", "database", "cache"]
# Cost-optimized NAT placement
nat_gateway_enabled: true
nat_gateway_public_subnet_names: ["nat"]
# VPC Flow Logs
vpc_flow_logs_enabled: true
vpc_flow_logs_bucket_environment_name: mgmt
vpc_flow_logs_bucket_stage_name: audit
vpc_flow_logs_traffic_type: "ALL"
# VPC Endpoints
gateway_vpc_endpoints:
- "s3"
- "dynamodb"
interface_vpc_endpoints:
- "ecr.api"
- "ecr.dkr"
- "logs"
subnet_type_tag_key: "example.net/subnet/type"
```
references:
- name: cloudposse-terraform-components
description: Cloud Posse's upstream component
url: https://github.com/orgs/cloudposse-terraform-components/repositories
- name: terraform-aws-vpc
description: CloudPosse VPC Module v3.0.0
url: https://github.com/cloudposse/terraform-aws-vpc
- name: terraform-aws-dynamic-subnets
description: CloudPosse Dynamic Subnets Module v3.1.0 - Enhanced subnet configuration with separate public/private control
url: https://github.com/cloudposse/terraform-aws-dynamic-subnets
- name: terraform-aws-dynamic-subnets v3.1.0 Release
description: Adds nat_gateway_private_ips output for NAT Gateway private IP addresses
url: https://github.com/cloudposse/terraform-aws-dynamic-subnets/releases/tag/v3.1.0
tags:
- component/vpc
- layer/network
- provider/aws
- nat-gateway
- subnets
- vpc-flow-logs
- vpc-endpoints
- cost-optimization
# Categories of this project
categories:
- component/vpc
- layer/network
- provider/aws
- networking
- infrastructure
# License of this project
license: "APACHE2"
# Badges to display
badges:
- name: Latest Release
image: https://img.shields.io/github/release/cloudposse-terraform-components/aws-vpc.svg?style=for-the-badge
url: https://github.com/cloudposse-terraform-components/aws-vpc/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"
- name: "terraform-aws-vpc"
description: "Terraform module for provisioning VPCs with advanced features"
url: "https://github.com/cloudposse/terraform-aws-vpc"
- name: "terraform-aws-dynamic-subnets"
description: "Terraform module for creating dynamic subnets with flexible configuration"
url: "https://github.com/cloudposse/terraform-aws-dynamic-subnets"
- name: "AWS VPC Documentation"
description: "Official AWS VPC documentation"
url: "https://docs.aws.amazon.com/vpc/"
- name: "AWS NAT Gateway Pricing"
description: "AWS NAT Gateway pricing for cost optimization planning"
url: "https://aws.amazon.com/vpc/pricing/"
contributors: [] # If included generates contribs