-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathterraform_workerlb.tf
90 lines (77 loc) · 2.6 KB
/
terraform_workerlb.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
variable "cluster_workerlb_types" {
type = list(string)
default = ["lb11", "lb11"]
}
variable "cluster_workerlb_locations" {
type = list(string)
default = ["nbg1", "fsn1"]
}
variable "cluster_network_ip_range_workerlb" {
type = string
default = "10.8.3.0/24"
}
locals {
cluster_workerlb_count = length(var.cluster_workerlb_types)
}
resource "hcloud_load_balancer" "workerlb" {
count = local.cluster_workerlb_count
name = format(local.cluster_resource_name, local.cluster_resource_name_workerlb, count.index + 1)
load_balancer_type = var.cluster_workerlb_types[count.index]
location = var.cluster_workerlb_locations[count.index]
labels = merge(local.labels, local.worker_labels)
algorithm {
type = "least_connections"
}
}
resource "hcloud_network_subnet" "network_subnet_workerlb" {
type = "cloud"
network_id = data.hcloud_network.network.id
network_zone = var.cluster_network_zone
ip_range = var.cluster_network_ip_range_workerlb
}
resource "hcloud_load_balancer_network" "workerlb_network" {
count = local.cluster_workerlb_count
load_balancer_id = hcloud_load_balancer.workerlb[count.index].id
network_id = data.hcloud_network.network.id
ip = cidrhost(hcloud_network_subnet.network_subnet_workerlb.ip_range, count.index + 1)
}
resource "hcloud_load_balancer_target" "workerlb_target" {
count = local.cluster_workerlb_count
type = "label_selector"
load_balancer_id = hcloud_load_balancer.workerlb[count.index].id
label_selector = "${var.cluster_label_key}=${var.cluster_name},${var.role_label_key}=${var.role_label_worker},${var.status_label_key}=${var.status_label_up}"
use_private_ip = true
depends_on = [
hcloud_load_balancer_network.workerlb_network
]
}
resource "hcloud_load_balancer_service" "workerlb_service_http" {
count = local.cluster_workerlb_count
load_balancer_id = hcloud_load_balancer.workerlb[count.index].id
protocol = "tcp"
listen_port = 80
destination_port = 80
proxyprotocol = true
health_check {
protocol = "tcp"
port = 80
interval = 10
timeout = 5
retries = 3
}
}
resource "hcloud_load_balancer_service" "workerlb_service_https" {
count = local.cluster_workerlb_count
load_balancer_id = hcloud_load_balancer.workerlb[count.index].id
protocol = "tcp"
listen_port = 443
destination_port = 443
proxyprotocol = true
health_check {
protocol = "tcp"
port = 443
interval = 10
timeout = 5
retries = 3
}
}