Skip to content

Commit 62b1991

Browse files
authored
Merge pull request #104 from pablo19sc/main
IPv6 support + minor updates in TGW routing
2 parents c88195d + a67936a commit 62b1991

33 files changed

+786
-214
lines changed

.header.md

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
# AWS VPC Module
22

3-
This module can be used to deploy a pragmatic VPC with various subnets types in # AZs. Common deployment examples can be found in [examples/](https://github.com/aws-ia/terraform-aws-vpc/tree/main/examples). Subnet CIDRs can be explicitly set via list of string argument `cidrs` or set via a number `netmask` argument.
3+
This module can be used to deploy a pragmatic VPC with various subnets types in # AZs. Common deployment examples can be found in [examples/](https://github.com/aws-ia/terraform-aws-vpc/tree/main/examples).
44

55
__Note: For information regarding the 4.0 upgrade see our [upgrade guide](https://github.com/aws-ia/terraform-aws-vpc/blob/main/UPGRADE-GUIDE-4.0.md).__
66

77
## Usage
88

9-
The example below builds a VPC with public and private subnets in 3 AZs. Each subnet calulates a CIDR based on the `netmask` argument passed. The public subnets build nat gateways in each AZ but optionally can be switched to `single_az`.
9+
The example below builds a dual-stack VPC with public and private subnets in 3 AZs. Each subnet calculates an IPv4 CIDR based on the `netmask` argument passed, and an IPv6 CIDR with a /64 prefix length. The public subnets build NAT gateways in each AZ but optionally can be switched to `single_az`. An Egress-only Internet gateway is created by using the variable `vpc_egress_only_internet_gateway`.
1010

1111
```hcl
1212
module "vpc" {
1313
source = "aws-ia/vpc/aws"
14-
version = ">= 4.0.0"
14+
version = ">= 4.2.0"
1515
16-
name = "multi-az-vpc"
17-
cidr_block = "10.0.0.0/20"
18-
az_count = 3
16+
name = "multi-az-vpc"
17+
cidr_block = "10.0.0.0/16"
18+
vpc_assign_generated_ipv6_cidr_block = true
19+
vpc_egress_only_internet_gateway = true
20+
az_count = 3
1921
2022
subnets = {
23+
# Dual-stack subnet
2124
public = {
2225
name_prefix = "my_public" # omit to prefix with "public"
2326
netmask = 24
27+
assign_ipv6_cidr = true
2428
nat_gateway_configuration = "all_azs" # options: "single_az", "none"
2529
}
26-
30+
# IPv4 only subnet
2731
private = {
2832
# omitting name_prefix defaults value to "private"
2933
# name_prefix = "private_with_egress"
3034
netmask = 24
3135
connect_to_public_natgw = true
3236
}
37+
# IPv6-only subnet
38+
private_ipv6 = {
39+
ipv6_native = true
40+
assign_ipv6_cidr = true
41+
connect_to_eigw = true
42+
}
3343
}
3444
3545
vpc_flow_logs = {
@@ -43,13 +53,7 @@ module "vpc" {
4353

4454
There are 3 reserved keys for subnet key names in var.subnets corresponding to types "public", "transit_gateway", and "core_network" [(an AWS Cloud WAN feature)](https://docs.aws.amazon.com/vpc/latest/cloudwan/cloudwan-networks-working-with.html). Other custom subnet key names are valid are and those subnets will be private subnets.
4555

46-
```terraform
47-
transit_gateway_id = <>
48-
transit_gateway_routes = {
49-
public = "pl-123"
50-
vpce = "10.0.0.0/8"
51-
}
52-
56+
```hcl
5357
subnets = {
5458
public = {
5559
name_prefix = "my-public" # omit to prefix with "public"
@@ -71,10 +75,28 @@ subnets = {
7175
# name_prefix = "private"
7276
netmask = 24
7377
}
78+
```
79+
80+
```hcl
81+
transit_gateway_id = <>
82+
transit_gateway_routes = {
83+
private = "0.0.0.0/0"
84+
vpce = "pl-123"
85+
}
86+
transit_gateway_ipv6_routes = {
87+
private = "::/0"
88+
}
89+
90+
subnets = {
91+
private = {
92+
netmask = 24
93+
assign_ipv6_cidr = true
94+
}
95+
vpce = { netmask = 24}
7496
7597
transit_gateway = {
7698
netmask = 28
77-
connect_to_public_natgw = true
99+
assign_ipv6_cidr = true
78100
transit_gateway_default_route_table_association = true
79101
transit_gateway_default_route_table_propagation = true
80102
transit_gateway_appliance_mode_support = "enable"
@@ -86,24 +108,28 @@ subnets = {
86108
}
87109
```
88110

89-
```terraform
111+
```hcl
90112
core_network = {
91113
id = <>
92114
arn = <>
93115
}
94116
core_network_routes = {
95117
workload = "pl-123"
96118
}
119+
core_network_ipv6_routes = {
120+
workload = "::/0"
121+
}
97122
98123
subnets = {
99124
workload = {
100-
name_prefix = "workload-private"
101-
netmask = 24
125+
name_prefix = "workload-private"
126+
netmask = 24
127+
assign_ipv6_cidr = true
102128
}
103129
104130
core_network = {
105131
netmask = 28
106-
ipv6_support = false
132+
assign_ipv6_cidr = true
107133
appliance_mode_support = false
108134
require_acceptance = true
109135
accept_attachment = true
@@ -116,40 +142,46 @@ subnets = {
116142

117143
## Updating a VPC with new or removed subnets
118144

119-
If using `netmask` to calculate subnets and you wish to either add or remove subnets (ex: adding / removing an AZ), you may have to change from using `netmask` for some subnets and set to explicit instead. Private subnets are always calculated before public.
145+
If using `netmask` or `assign_ipv6_cidr` to calculate subnets and you wish to either add or remove subnets (ex: adding / removing an AZ), you may have to change from using `netmask` / `assign_ipv6_cidr` for some subnets and set to explicit instead. Private subnets are always calculated before public.
120146

121147
When changing to explicit cidrs, subnets are always ordered by AZ. `0` -> a, `1` -> b, etc.
122148

123149
Example: Changing from 2 azs to 3
124150

125151
Before:
126152
```hcl
127-
cidr_block = "10.0.0.0/16"
128-
az_count = 2
153+
cidr_block = "10.0.0.0/16"
154+
vpc_assign_generated_ipv6_cidr_block = true
155+
az_count = 2
129156
130157
subnets = {
131158
public = {
132-
netmask = 24
159+
netmask = 24
160+
assign_ipv6_cidr = true
133161
}
134162
135163
private = {
136-
netmask = 24
164+
netmask = 24
165+
assign_ipv6_cidr = true
137166
}
138167
}
139168
```
140169

141170
After:
142171
```hcl
143-
cidr_block = "10.0.0.0/16"
172+
cidr_block = "10.0.0.0/16"
173+
vpc_assign_generated_ipv6_cidr_block = true
144174
az_count = 3
145175
146176
subnets = {
147177
public = {
148-
cidrs = ["10.0.0.0/24", "10.0.1.0/24", "10.0.4.0/24"]
178+
cidrs = ["10.0.0.0/24", "10.0.1.0/24", "10.0.4.0/24"]
179+
ipv6_cidrs = ["2a05:d01c:bc3:b200::/64", "2a05:d01c:bc3:b201::/64", "2a05:d01c:bc3:b204::/64"]
149180
}
150181
151182
private = {
152-
cidrs = ["10.0.2.0/24", "10.0.3.0/24", "10.0.5.0/24"]
183+
cidrs = ["10.0.2.0/24", "10.0.3.0/24", "10.0.5.0/24"]
184+
ipv6_cidrs = ["2a05:d01c:bc3:b202::/64", "2a05:d01c:bc3:b203::/64", "2a05:d01c:bc3:b205::/64"]
153185
}
154186
}
155187
```
@@ -166,7 +198,7 @@ Example Configuration:
166198
```terraform
167199
module "vpc" {
168200
source = "aws-ia/vpc/aws"
169-
version = ">= 4.0.0"
201+
version = ">= 4.2.0"
170202
171203
name = "multi-az-vpc"
172204
cidr_block = "10.0.0.0/20"
@@ -228,6 +260,7 @@ This happens when the Core Network's VPC attachment requires acceptance, so it's
228260
subnets = {
229261
core_network = {
230262
netmask = 28
263+
assign_ipv6_cidr = true
231264
require_acceptance = true
232265
accept_attachment = true
233266
}
@@ -240,6 +273,7 @@ subnets = {
240273
subnets = {
241274
core_network = {
242275
netmask = 28
276+
assign_ipv6_cidr = true
243277
require_acceptance = true
244278
accept_attachment = true
245279
}
@@ -252,6 +286,7 @@ After you apply and the attachment is accepted (outside the module), change the
252286
subnets = {
253287
core_network = {
254288
netmask = 28
289+
assign_ipv6_cidr = true
255290
require_acceptance = false
256291
}
257292
}
@@ -261,4 +296,4 @@ subnets = {
261296

262297
# Contributing
263298

264-
Please see our [developer documentation](https://github.com/aws-ia/terraform-aws-vpc/blob/main/contributing.md) for guidance on contributing to this module
299+
Please see our [developer documentation](https://github.com/aws-ia/terraform-aws-vpc/blob/main/contributing.md) for guidance on contributing to this module.

0 commit comments

Comments
 (0)