-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
nat-gateway.tf
72 lines (57 loc) · 2.42 KB
/
nat-gateway.tf
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
module "nat_label" {
source = "cloudposse/label/null"
version = "0.25.0"
attributes = ["nat"]
context = module.this.context
}
resource "aws_nat_gateway" "default" {
count = local.nat_gateway_enabled ? local.nat_count : 0
allocation_id = local.nat_eip_allocations[count.index]
subnet_id = aws_subnet.public[count.index].id
tags = merge(
module.nat_label.tags,
{
"Name" = format("%s%s%s", module.nat_label.id, local.delimiter, local.subnet_az_abbreviations[count.index])
}
)
depends_on = [aws_eip_association.nat_instance]
}
# If private IPv4 subnets and NAT Gateway are both enabled, create a
# default route from private subnet to NAT Gateway in each subnet
resource "aws_route" "nat4" {
count = local.nat_gateway_enabled && local.private4_enabled ? local.private_route_table_count : 0
route_table_id = local.private_route_table_ids[count.index]
nat_gateway_id = element(aws_nat_gateway.default[*].id, count.index)
destination_cidr_block = "0.0.0.0/0"
depends_on = [aws_route_table.private]
timeouts {
create = local.route_create_timeout
delete = local.route_delete_timeout
}
}
# If private IPv6 subnet needs NAT64 and NAT Gateway is enabled, create a
# NAT64 route from private subnet to NAT Gateway in each subnet
resource "aws_route" "private_nat64" {
count = local.nat_gateway_enabled && local.private_dns64_enabled ? local.private_route_table_count : 0
route_table_id = local.private_route_table_ids[count.index]
nat_gateway_id = element(aws_nat_gateway.default[*].id, count.index)
destination_ipv6_cidr_block = local.nat64_cidr
depends_on = [aws_route_table.private]
timeouts {
create = local.route_create_timeout
delete = local.route_delete_timeout
}
}
# If public IPv6 subnet needs NAT64 and NAT Gateway is enabled, create a
# NAT64 route from private subnet to NAT Gateway in each subnet
resource "aws_route" "public_nat64" {
count = local.nat_gateway_enabled && local.public_dns64_enabled ? local.public_route_table_count : 0
route_table_id = local.public_route_table_ids[count.index]
nat_gateway_id = element(aws_nat_gateway.default[*].id, count.index)
destination_ipv6_cidr_block = local.nat64_cidr
depends_on = [aws_route_table.public]
timeouts {
create = local.route_create_timeout
delete = local.route_delete_timeout
}
}