-
Notifications
You must be signed in to change notification settings - Fork 5
/
terraform_workernode.tf
54 lines (46 loc) · 1.93 KB
/
terraform_workernode.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
variable "cluster_workernode_types" {
type = list(string)
default = ["cx21", "cx21", "cx21"]
}
variable "cluster_workernode_locations" {
type = list(string)
default = ["nbg1", "fsn1", "hel1"]
}
variable "cluster_network_ip_range_workernode" {
type = string
default = "10.8.11.0/24"
}
locals {
cluster_workernode_count = length(var.cluster_workernode_types)
}
resource "hcloud_server" "workernode" {
count = local.cluster_workernode_count
name = format(local.cluster_resource_name, local.cluster_resource_name_workernode, count.index + 1)
image = var.cluster_node_image
server_type = var.cluster_workernode_types[count.index]
location = var.cluster_workernode_locations[count.index]
placement_group_id = var.cluster_use_placement_group ? hcloud_placement_group.placement_group.0.id : null
ssh_keys = var.cluster_authorized_ssh_keys
labels = merge(local.labels, local.worker_labels, local.node_labels)
firewall_ids = [
hcloud_firewall.nodefw.id
]
}
resource "hcloud_network_subnet" "network_subnet_workernode" {
type = "cloud"
network_id = data.hcloud_network.network.id
network_zone = var.cluster_network_zone
ip_range = var.cluster_network_ip_range_workernode
}
resource "hcloud_server_network" "workernode_network" {
count = local.cluster_workernode_count
server_id = hcloud_server.workernode[count.index].id
network_id = data.hcloud_network.network.id
ip = cidrhost(hcloud_network_subnet.network_subnet_workernode.ip_range, count.index + 1)
}
resource "hcloud_network_route" "workernode_pods" {
count = var.install_hcloud_ccm ? 0 : local.cluster_workernode_count
network_id = data.hcloud_network.network.id
destination = cidrsubnet(cidrsubnet(var.cluster_network_ip_range_pod, 1, 1), 8, count.index + 1)
gateway = hcloud_server_network.workernode_network[count.index].ip
}