This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subnet_private.tf
116 lines (93 loc) · 3.35 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
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
resource "aws_subnet" "private" {
count = length(data.aws_availability_zones.this.names)
vpc_id = aws_vpc.this.id
availability_zone = data.aws_availability_zones.this.names[count.index]
map_public_ip_on_launch = false
cidr_block = cidrsubnet(
aws_vpc.this.cidr_block,
ceil(log(length(var.subnets), 2)) + ceil(log(length(data.aws_availability_zones.this.names), 2)),
index(var.subnets, "private") * length(data.aws_availability_zones.this.names) + count.index
)
tags = merge(var.tags,
{
Name = "${var.name}-private-${data.aws_availability_zones.this.names[count.index]}"
SubnetType = "private"
},
{
"kubernetes.io/cluster/${var.name}" = "owned"
}
)
}
resource "aws_route_table" "private" {
count = length(aws_subnet.private)
vpc_id = aws_vpc.this.id
tags = merge(var.tags,
{
Name = "${var.name}-private-${data.aws_availability_zones.this.names[count.index]}"
}
)
}
resource "aws_route" "private" {
count = length(aws_subnet.private)
route_table_id = aws_route_table.private[count.index].id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.this[count.index].id
}
resource "aws_route_table_association" "private" {
count = length(aws_subnet.private)
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private[count.index].id
}
resource "aws_flow_log" "private" {
count = var.enable_flow_logs ? length(data.aws_availability_zones.this.names) : 0
iam_role_arn = aws_iam_role.vpc_flow_logs[0].arn
log_destination = aws_cloudwatch_log_group.vpc_flow_logs[0].arn
traffic_type = var.flow_log_traffic_type
subnet_id = aws_subnet.private[count.index].id
}
resource "aws_network_acl" "private" {
count = var.enable_network_acls ? length(data.aws_availability_zones.this.names) : 0
vpc_id = aws_vpc.this.id
subnet_ids = [aws_subnet.private[count.index].id]
tags = merge(var.tags,
{
Name = "${var.name}-private-${data.aws_availability_zones.this.names[count.index]}"
}
)
}
# TODO: Restrict this
resource "aws_network_acl_rule" "private_egress_all" {
count = var.enable_network_acls ? length(data.aws_availability_zones.this.names) : 0
network_acl_id = aws_network_acl.private[count.index].id
rule_number = 1
egress = true
protocol = "all"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
}
# TODO: Restrict this
resource "aws_network_acl_rule" "private_ingress_all" {
count = var.enable_network_acls ? length(data.aws_availability_zones.this.names) : 0
network_acl_id = aws_network_acl.private[count.index].id
rule_number = 1
egress = false
protocol = "all"
rule_action = "allow"
cidr_block = "0.0.0.0/0"
}
# # TODO: Enable more restricted rules like this.
# # Allow HTTPS inbound traffic from load balancer subnet
# resource "aws_network_acl_rule" "private_ingress_https" {
# network_acl_id = aws_network_acl.private.id
# rule_number = aws_network_acl_rule.private_egress.rule_number + 1
# egress = false
# protocol = "tcp"
# rule_action = "allow"
# cidr_block = cidrsubnet(
# aws_vpc.this.cidr_block,
# ceil(log(length(var.subnets), 2)),
# index(var.subnets, "public")
# )
# from_port = 443
# to_port = 443
# }