@@ -28,7 +28,7 @@ resource "aws_vpc" "this" {
28
28
instance_tenancy = var. instance_tenancy
29
29
enable_dns_hostnames = var. enable_dns_hostnames
30
30
enable_dns_support = var. enable_dns_support
31
- assign_generated_ipv6_cidr_block = var. assign_generated_ipv6_cidr_block
31
+ assign_generated_ipv6_cidr_block = var. enable_ipv6
32
32
33
33
tags = merge (
34
34
{
@@ -95,6 +95,12 @@ resource "aws_internet_gateway" "this" {
95
95
)
96
96
}
97
97
98
+ resource "aws_egress_only_internet_gateway" "this" {
99
+ count = var. create_vpc && var. enable_ipv6 && local. max_subnet_length > 0 ? 1 : 0
100
+
101
+ vpc_id = local. vpc_id
102
+ }
103
+
98
104
# ###############
99
105
# Publiс routes
100
106
# ###############
@@ -124,6 +130,14 @@ resource "aws_route" "public_internet_gateway" {
124
130
}
125
131
}
126
132
133
+ resource "aws_route" "public_internet_gateway_ipv6" {
134
+ count = var. create_vpc && var. enable_ipv6 && length (var. public_subnets ) > 0 ? 1 : 0
135
+
136
+ route_table_id = aws_route_table. public [0 ]. id
137
+ destination_ipv6_cidr_block = " ::/0"
138
+ gateway_id = aws_internet_gateway. this [0 ]. id
139
+ }
140
+
127
141
# ################
128
142
# Private routes
129
143
# There are as many routing tables as the number of NAT gateways
@@ -193,6 +207,18 @@ resource "aws_route" "database_nat_gateway" {
193
207
}
194
208
}
195
209
210
+ resource "aws_route" "database_ipv6_egress" {
211
+ count = var. create_vpc && var. enable_ipv6 && var. create_database_subnet_route_table && length (var. database_subnets ) > 0 && var. create_database_internet_gateway_route ? 1 : 0
212
+
213
+ route_table_id = aws_route_table. database [0 ]. id
214
+ destination_ipv6_cidr_block = " ::/0"
215
+ egress_only_gateway_id = aws_egress_only_internet_gateway. this [0 ]. id
216
+
217
+ timeouts {
218
+ create = " 5m"
219
+ }
220
+ }
221
+
196
222
# ################
197
223
# Redshift routes
198
224
# ################
@@ -250,10 +276,13 @@ resource "aws_route_table" "intra" {
250
276
resource "aws_subnet" "public" {
251
277
count = var. create_vpc && length (var. public_subnets ) > 0 && (false == var. one_nat_gateway_per_az || length (var. public_subnets ) >= length (var. azs )) ? length (var. public_subnets ) : 0
252
278
253
- vpc_id = local. vpc_id
254
- cidr_block = element (concat (var. public_subnets , [" " ]), count. index )
255
- availability_zone = element (var. azs , count. index )
256
- map_public_ip_on_launch = var. map_public_ip_on_launch
279
+ vpc_id = local. vpc_id
280
+ cidr_block = element (concat (var. public_subnets , [" " ]), count. index )
281
+ availability_zone = element (var. azs , count. index )
282
+ map_public_ip_on_launch = var. map_public_ip_on_launch
283
+ assign_ipv6_address_on_creation = var. public_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. public_subnet_assign_ipv6_address_on_creation
284
+
285
+ ipv6_cidr_block = var. enable_ipv6 && length (var. public_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. public_subnet_ipv6_prefixes [count . index ]) : null
257
286
258
287
tags = merge (
259
288
{
@@ -274,9 +303,12 @@ resource "aws_subnet" "public" {
274
303
resource "aws_subnet" "private" {
275
304
count = var. create_vpc && length (var. private_subnets ) > 0 ? length (var. private_subnets ) : 0
276
305
277
- vpc_id = local. vpc_id
278
- cidr_block = var. private_subnets [count . index ]
279
- availability_zone = element (var. azs , count. index )
306
+ vpc_id = local. vpc_id
307
+ cidr_block = var. private_subnets [count . index ]
308
+ availability_zone = element (var. azs , count. index )
309
+ assign_ipv6_address_on_creation = var. private_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. private_subnet_assign_ipv6_address_on_creation
310
+
311
+ ipv6_cidr_block = var. enable_ipv6 && length (var. private_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. private_subnet_ipv6_prefixes [count . index ]) : null
280
312
281
313
tags = merge (
282
314
{
@@ -297,9 +329,12 @@ resource "aws_subnet" "private" {
297
329
resource "aws_subnet" "database" {
298
330
count = var. create_vpc && length (var. database_subnets ) > 0 ? length (var. database_subnets ) : 0
299
331
300
- vpc_id = local. vpc_id
301
- cidr_block = var. database_subnets [count . index ]
302
- availability_zone = element (var. azs , count. index )
332
+ vpc_id = local. vpc_id
333
+ cidr_block = var. database_subnets [count . index ]
334
+ availability_zone = element (var. azs , count. index )
335
+ assign_ipv6_address_on_creation = var. database_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. database_subnet_assign_ipv6_address_on_creation
336
+
337
+ ipv6_cidr_block = var. enable_ipv6 && length (var. database_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. database_subnet_ipv6_prefixes [count . index ]) : null
303
338
304
339
tags = merge (
305
340
{
@@ -336,9 +371,12 @@ resource "aws_db_subnet_group" "database" {
336
371
resource "aws_subnet" "redshift" {
337
372
count = var. create_vpc && length (var. redshift_subnets ) > 0 ? length (var. redshift_subnets ) : 0
338
373
339
- vpc_id = local. vpc_id
340
- cidr_block = var. redshift_subnets [count . index ]
341
- availability_zone = element (var. azs , count. index )
374
+ vpc_id = local. vpc_id
375
+ cidr_block = var. redshift_subnets [count . index ]
376
+ availability_zone = element (var. azs , count. index )
377
+ assign_ipv6_address_on_creation = var. redshift_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. redshift_subnet_assign_ipv6_address_on_creation
378
+
379
+ ipv6_cidr_block = var. enable_ipv6 && length (var. redshift_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. redshift_subnet_ipv6_prefixes [count . index ]) : null
342
380
343
381
tags = merge (
344
382
{
@@ -375,9 +413,12 @@ resource "aws_redshift_subnet_group" "redshift" {
375
413
resource "aws_subnet" "elasticache" {
376
414
count = var. create_vpc && length (var. elasticache_subnets ) > 0 ? length (var. elasticache_subnets ) : 0
377
415
378
- vpc_id = local. vpc_id
379
- cidr_block = var. elasticache_subnets [count . index ]
380
- availability_zone = element (var. azs , count. index )
416
+ vpc_id = local. vpc_id
417
+ cidr_block = var. elasticache_subnets [count . index ]
418
+ availability_zone = element (var. azs , count. index )
419
+ assign_ipv6_address_on_creation = var. elasticache_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. elasticache_subnet_assign_ipv6_address_on_creation
420
+
421
+ ipv6_cidr_block = var. enable_ipv6 && length (var. elasticache_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. elasticache_subnet_ipv6_prefixes [count . index ]) : null
381
422
382
423
tags = merge (
383
424
{
@@ -406,9 +447,12 @@ resource "aws_elasticache_subnet_group" "elasticache" {
406
447
resource "aws_subnet" "intra" {
407
448
count = var. create_vpc && length (var. intra_subnets ) > 0 ? length (var. intra_subnets ) : 0
408
449
409
- vpc_id = local. vpc_id
410
- cidr_block = var. intra_subnets [count . index ]
411
- availability_zone = element (var. azs , count. index )
450
+ vpc_id = local. vpc_id
451
+ cidr_block = var. intra_subnets [count . index ]
452
+ availability_zone = element (var. azs , count. index )
453
+ assign_ipv6_address_on_creation = var. intra_subnet_assign_ipv6_address_on_creation == null ? var. assign_ipv6_address_on_creation : var. intra_subnet_assign_ipv6_address_on_creation
454
+
455
+ ipv6_cidr_block = var. enable_ipv6 && length (var. intra_subnet_ipv6_prefixes ) > 0 ? cidrsubnet (aws_vpc. this [0 ]. ipv6_cidr_block , 8 , var. intra_subnet_ipv6_prefixes [count . index ]) : null
412
456
413
457
tags = merge (
414
458
{
@@ -824,6 +868,14 @@ resource "aws_route" "private_nat_gateway" {
824
868
}
825
869
}
826
870
871
+ resource "aws_route" "private_ipv6_egress" {
872
+ count = var. enable_ipv6 ? length (var. private_subnets ) : 0
873
+
874
+ route_table_id = element (aws_route_table. private . * . id , count. index )
875
+ destination_ipv6_cidr_block = " ::/0"
876
+ egress_only_gateway_id = element (aws_egress_only_internet_gateway. this . * . id , 0 )
877
+ }
878
+
827
879
# #####################
828
880
# VPC Endpoint for S3
829
881
# #####################
0 commit comments