-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnodes.tf
executable file
·78 lines (65 loc) · 2.37 KB
/
nodes.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
# Worker nodes with docker as the default container runtime
resource "hcloud_server" "worker" {
count = var.worker_nodes_count
name = "worker-${count.index}"
image = data.hcloud_image.k8s_image.id
server_type = var.worker_server_type
location = var.worker_location
ssh_keys = [hcloud_ssh_key.default.name]
}
resource "hcloud_server_network" "worker_networks" {
count = var.worker_nodes_count
server_id = hcloud_server.worker[count.index].id
network_id = hcloud_network.mynet.id
ip = "10.0.1.${6 + count.index}" // Consecutive IP addresses starting from 10.0.1.5 (master node IP address).
}
# Worker nodes with containerd as the default container runtime
resource "hcloud_server" "workercontainerd" {
count = var.worker_nodes_containerd_count
name = "worker-containerd-${count.index}"
image = data.hcloud_image.k8s_image_containerd.id
server_type = var.worker_containerd_server_type
location = var.worker_containerd_location
ssh_keys = [hcloud_ssh_key.default.name]
}
resource "hcloud_server_network" "worker_containerd_networks" {
count = var.worker_nodes_containerd_count
server_id = hcloud_server.workercontainerd[count.index].id
network_id = hcloud_network.mynet.id
ip = "10.0.1.${17 + count.index}"
}
resource "null_resource" "k8s_workers" {
count = var.worker_nodes_count
triggers = {
# hcloud_server_worker_names = "${join(",", hcloud_server.worker.*.name)}"
hcloud_server_worker_names = hcloud_server.worker[count.index].name
}
connection {
type = "ssh"
host = hcloud_server.worker[count.index].ipv4_address
user = "root"
private_key = file("~/.ssh/id_rsa")
}
provisioner "remote-exec" {
inline = [
data.external.kubeadm_join.result.command
]
}
}
resource "null_resource" "k8s_workers_containerd" {
count = var.worker_nodes_containerd_count
triggers = {
hcloud_server_workercontainerd_names = hcloud_server.workercontainerd[count.index].name
}
connection {
type = "ssh"
host = hcloud_server.workercontainerd[count.index].ipv4_address
user = "root"
private_key = file("~/.ssh/id_rsa")
}
provisioner "remote-exec" {
inline = [
data.external.kubeadm_join.result.command
]
}
}