forked from DNXLabs/terraform-aws-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subnet-private.tf
80 lines (68 loc) · 2.61 KB
/
subnet-private.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
73
74
75
76
77
78
79
80
resource "aws_subnet" "private" {
count = length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
vpc_id = aws_vpc.default.id
cidr_block = cidrsubnet(
aws_vpc.default.cidr_block,
var.newbits,
count.index + var.private_netnum_offset,
)
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = false
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].subnet_private, var.name, upper(data.aws_availability_zone.az[count.index].name_suffix), local.name_suffix)
"Scheme" = "private"
"EnvName" = var.name
"aws-cdk:subnet-name" = "Private"
"aws-cdk:subnet-type" = "Private"
},
local.kubernetes_clusters,
length(var.kubernetes_clusters) != 0 ? { "kubernetes.io/role/internal-elb" = 1 } : {}
)
}
resource "aws_route_table" "private" {
count = var.nat && var.multi_nat ? (
length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
) : 1
vpc_id = aws_vpc.default.id
tags = merge(
var.tags,
{
"Name" = format(local.names[var.name_pattern].routetable_private, var.name, count.index, local.name_suffix)
"Scheme" = "private"
"EnvName" = var.name
},
)
}
resource "aws_route" "nat_route" {
count = var.nat && var.multi_nat ? (
length(data.aws_availability_zones.available.names) > var.max_az ? var.max_az : length(data.aws_availability_zones.available.names)
) : (var.nat ? 1 : 0)
route_table_id = aws_route_table.private[count.index].id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gw[count.index].id
lifecycle {
create_before_destroy = true
}
depends_on = [aws_nat_gateway.nat_gw]
}
resource "aws_route_table_association" "private" {
count = length(aws_subnet.private)
subnet_id = aws_subnet.private[count.index].id
route_table_id = var.multi_nat ? aws_route_table.private[count.index].id : aws_route_table.private[0].id
lifecycle {
ignore_changes = [subnet_id]
create_before_destroy = true
}
}
# resource "aws_route_table_association" "private_single" {
# count = var.nat_count == length(data.aws_availability_zones.available.names) ? 0 : 1
# subnet_id = aws_subnet.private.*.id[count.index]
# route_table_id = aws_route_table.private.*.id[count.index]
#
# lifecycle {
# ignore_changes = ["subnet_id"]
# create_before_destroy = true
# }
# }