-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathprivate_subnet.tf
75 lines (58 loc) · 2.08 KB
/
private_subnet.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
data "aws_availability_zones" "available" {}
resource "aws_subnet" "private" {
count = 2
availability_zone = var.zones[count.index]
cidr_block = var.cidr_block_private_subnet[count.index]
vpc_id = aws_vpc.vpc.id
tags = merge(local.tags, {
"Name" = "${var.environment_name}-private"
"kubernetes.io/cluster/${var.environment_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
"karpenter.sh/discovery" = "true"
})
}
resource "aws_eip" "eips" {
count = var.nat_enabled && length(var.eips) == 0 ? 2 : 0
tags = merge(local.tags, {
"Name" = "${var.environment_name}-${count.index}"
})
}
resource "aws_nat_gateway" "gw" {
count = var.nat_enabled ? 2 : 0
allocation_id = length(var.eips) == 0 ? aws_eip.eips[count.index].id : var.eips[count.index].id
subnet_id = aws_subnet.public[count.index].id
tags = merge(local.tags, {
"Name" = var.environment_name
})
}
resource "aws_route_table" "private" {
count = 2
vpc_id = aws_vpc.vpc.id
tags = merge(local.tags, {
Name = "${var.environment_name}-private-${count.index}"
})
}
resource "aws_route" "nat" {
count = var.nat_enabled ? 2 : 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.gw[count.index].id
}
resource "aws_route" "ipv6" {
count = var.enable_egress_only_internet_gateway ? 2 : 0
route_table_id = aws_route_table.private[count.index].id
destination_ipv6_cidr_block = "::/0"
egress_only_gateway_id = aws_egress_only_internet_gateway.egress[0].id
}
resource "aws_egress_only_internet_gateway" "egress" {
count = var.enable_egress_only_internet_gateway ? 1 : 0
vpc_id = aws_vpc.vpc.id
tags = merge(local.tags, {
Name = "${var.environment_name}-egress-${count.index}"
})
}
resource "aws_route_table_association" "private" {
count = 2
subnet_id = aws_subnet.private[count.index].id
route_table_id = aws_route_table.private[count.index].id
}