forked from rancher/terraform-k3s-aws-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadbalancer.tf
109 lines (92 loc) · 2.69 KB
/
loadbalancer.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
resource "random_pet" "lb" {}
resource "aws_lb" "server-lb" {
name = substr("${local.name}-int-${random_pet.lb.id}", 0, 24)
internal = true
load_balancer_type = "network"
subnets = local.private_subnets
}
resource "aws_lb_listener" "server-port_6443" {
load_balancer_arn = aws_lb.server-lb.arn
port = "6443"
protocol = "TCP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.server-6443.arn
}
}
resource "aws_lb_target_group" "server-6443" {
name = substr("${local.name}-6443-${random_pet.lb.id}", 0, 24)
port = 6443
protocol = "TCP"
vpc_id = data.aws_vpc.default.id
}
resource "aws_lb" "lb" {
count = local.create_external_nlb
name = substr("${local.name}-ext-${random_pet.lb.id}", 0, 24)
internal = false
load_balancer_type = "network"
subnets = local.public_subnets
tags = {
"kubernetes.io/cluster/${local.name}" = ""
}
}
resource "aws_lb_listener" "port_443" {
count = local.create_external_nlb
load_balancer_arn = aws_lb.lb.0.arn
port = "443"
protocol = "TCP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.agent-443.0.arn
}
}
resource "aws_lb_listener" "port_80" {
count = local.create_external_nlb
load_balancer_arn = aws_lb.lb.0.arn
port = "80"
protocol = "TCP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.agent-80.0.arn
}
}
resource "aws_lb_target_group" "agent-443" {
count = local.create_external_nlb
name = substr("${local.name}-443-${random_pet.lb.id}", 0, 24)
port = 443
protocol = "TCP"
vpc_id = data.aws_vpc.default.id
health_check {
interval = 10
timeout = 6
path = "/healthz"
port = 80
protocol = "HTTP"
healthy_threshold = 3
unhealthy_threshold = 3
matcher = "200-399"
}
tags = {
"kubernetes.io/cluster/${local.name}" = ""
}
}
resource "aws_lb_target_group" "agent-80" {
count = local.create_external_nlb
name = substr("${local.name}-80-${random_pet.lb.id}", 0, 24)
port = 80
protocol = "TCP"
vpc_id = data.aws_vpc.default.id
health_check {
interval = 10
timeout = 6
path = "/healthz"
port = 80
protocol = "HTTP"
healthy_threshold = 3
unhealthy_threshold = 3
matcher = "200-399"
}
tags = {
"kubernetes.io/cluster/${local.name}" = ""
}
}