-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathREADME.yaml
325 lines (293 loc) · 10.6 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#
# Name of this project
name: terraform-aws-named-subnets
# Logo for this project
#logo: docs/logo.png
# License of this project
license: "APACHE2"
# Tags of this project
tags:
- aws
- terraform
- terraform-modules
- networking
- named-subnets
- availability-zone
- subnet
- vpc
- cidr
- dynamic
# Categories of this project
categories:
- terraform-modules/networking
# Canonical GitHub repo
github_repo: cloudposse/terraform-aws-named-subnets
# Badges to display
badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-named-subnets.svg"
url: "https://github.com/cloudposse/terraform-aws-named-subnets/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"
related:
- name: "terraform-aws-multi-az-subnets"
description: "Terraform module for multi-AZ public and private subnets provisioning."
url: "https://github.com/cloudposse/terraform-aws-multi-az-subnets"
- name: "terraform-aws-dynamic-subnets"
description: "Terraform module for public and private subnets provisioning in existing VPC"
url: "https://github.com/cloudposse/terraform-aws-dynamic-subnets"
- name: "terraform-aws-vpc"
description: "Terraform Module that defines a VPC with public/private subnets across multiple AZs with Internet Gateways"
url: "https://github.com/cloudposse/terraform-aws-vpc"
- name: "terraform-aws-cloudwatch-flow-logs"
description: "Terraform module for enabling flow logs for vpc and subnets."
url: "https://github.com/cloudposse/terraform-aws-cloudwatch-flow-logs"
# Short description of this project
description: |-
Terraform module for named [`subnets`](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Subnets.html) provisioning.
# How to use this project
usage: |2-
Simple example, with private and public subnets in one Availability Zone:
```hcl
module "vpc" {
source = "cloudposse/vpc/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
name = "vpc"
stage = "dev"
cidr_block = var.cidr_block
}
locals {
public_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 1, 0)
private_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 1, 1)
}
module "public_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["web1", "web2", "web3"]
vpc_id = module.vpc.vpc_id
cidr_block = local.public_cidr_block
type = "public"
igw_id = module.vpc.igw_id
availability_zone = "us-east-1a"
}
module "private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "database"
subnet_names = ["kafka", "cassandra", "zookeeper"]
vpc_id = module.vpc.vpc_id
cidr_block = local.private_cidr_block
type = "private"
availability_zone = "us-east-1a"
ngw_id = module.public_subnets.ngw_id
}
```
Simple example, with `ENI` as default route gateway for private subnets
```hcl
resource "aws_network_interface" "default" {
subnet_id = module.us_east_1b_public_subnets.subnet_ids[0]
source_dest_check = false
tags = module.network_interface_label.id
}
module "us_east_1b_private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["charlie", "echo", "bravo"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1b_private_cidr_block
type = "private"
availability_zone = "us-east-1b"
eni_id = aws_network_interface.default.id
attributes = ["us-east-1b"]
}
```
Full example, with private and public subnets in two Availability Zones for High Availability:
```hcl
module "vpc" {
source = "cloudposse/vpc/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
name = "vpc"
stage = "dev"
cidr_block = var.cidr_block
}
locals {
us_east_1a_public_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 2, 0)
us_east_1a_private_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 2, 1)
us_east_1b_public_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 2, 2)
us_east_1b_private_cidr_block = cidrsubnet(module.vpc.vpc_cidr_block, 2, 3)
}
module "us_east_1a_public_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["apples", "oranges", "grapes"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1a_public_cidr_block
type = "public"
igw_id = module.vpc.igw_id
availability_zone = "us-east-1a"
attributes = ["us-east-1a"]
}
module "us_east_1a_private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["charlie", "echo", "bravo"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1a_private_cidr_block
type = "private"
availability_zone = "us-east-1a"
ngw_id = module.us_east_1a_public_subnets.ngw_id
attributes = ["us-east-1a"]
}
module "us_east_1b_public_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["apples", "oranges", "grapes"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1b_public_cidr_block
type = "public"
igw_id = module.vpc.igw_id
availability_zone = "us-east-1b"
attributes = ["us-east-1b"]
}
module "us_east_1b_private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["charlie", "echo", "bravo"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1b_private_cidr_block
type = "private"
availability_zone = "us-east-1b"
ngw_id = module.us_east_1b_public_subnets.ngw_id
attributes = ["us-east-1b"]
}
resource "aws_network_interface" "default" {
subnet_id = module.us_east_1b_public_subnets.subnet_ids[0]
source_dest_check = false
tags = module.network_interface_label.id
}
module "us_east_1b_private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["charlie", "echo", "bravo"]
vpc_id = module.vpc.vpc_id
cidr_block = local.us_east_1b_private_cidr_block
type = "private"
availability_zone = "us-east-1b"
eni_id = aws_network_interface.default.id
attributes = ["us-east-1b"]
}
```
## Caveat
You must use only one type of device for a default route gateway per route table. `ENI` or `NGW`
Given the following configuration (see the Simple example above)
```hcl
locals {
public_cidr_block = cidrsubnet(var.vpc_cidr, 1, 0)
private_cidr_block = cidrsubnet(var.vpc_cidr, 1, 1)
}
module "public_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "app"
subnet_names = ["web1", "web2", "web3"]
vpc_id = var.vpc_id
cidr_block = local.public_cidr_block
type = "public"
availability_zone = "us-east-1a"
igw_id = var.igw_id
}
module "private_subnets" {
source = "cloudposse/named-subnets/aws"
# Cloud Posse recommends pinning every module to a specific version
# version = "x.x.x"
namespace = "eg"
stage = "dev"
name = "database"
subnet_names = ["kafka", "cassandra", "zookeeper"]
vpc_id = var.vpc_id
cidr_block = local.private_cidr_block
type = "private"
availability_zone = "us-east-1a"
ngw_id = module.public_subnets.ngw_id
}
output "private_named_subnet_ids" {
value = module.private_subnets.named_subnet_ids
}
output "public_named_subnet_ids" {
value = module.public_subnets.named_subnet_ids
}
```
the output Maps of subnet names to subnet IDs look like these
```hcl
public_named_subnet_ids = {
web1 = subnet-ea58d78e
web2 = subnet-556ee131
web3 = subnet-6f54db0b
}
private_named_subnet_ids = {
cassandra = subnet-376de253
kafka = subnet-9e53dcfa
zookeeper = subnet-a86fe0cc
}
```
and the created subnet IDs could be found by the subnet names using `map["key"]` or [`lookup(map, key, [default])`](https://www.terraform.io/docs/configuration/interpolation.html#lookup-map-key-default-),
for example:
`public_named_subnet_ids["web1"]`
`lookup(private_named_subnet_ids, "kafka")`
include:
- "docs/targets.md"
- "docs/terraform.md"
# Contributors to this project
contributors:
- name: "Erik Osterman"
github: "osterman"
- name: "Andriy Knysh"
github: "aknysh"
- name: "Sergey Vasilyev"
github: "s2504s"
- name: "Vladimir"
github: "SweetOps"
- name: "Konstantin B"
github: "comeanother"