-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.tf
executable file
·107 lines (87 loc) · 2.55 KB
/
main.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
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_ssh_key" "k8s_admin" {
name = "k8s_admin"
public_key = file(var.ssh_public_key)
}
resource "hcloud_server" "master" {
count = var.master_count
name = "master-${count.index + 1}"
server_type = var.master_type
image = var.master_image
ssh_keys = [hcloud_ssh_key.k8s_admin.id]
connection {
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "files/10-kubeadm.conf"
destination = "/root/10-kubeadm.conf"
}
provisioner "file" {
source = "scripts/bootstrap.sh"
destination = "/root/bootstrap.sh"
}
provisioner "remote-exec" {
inline = ["DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"]
}
provisioner "file" {
source = "scripts/master.sh"
destination = "/root/master.sh"
}
provisioner "remote-exec" {
inline = ["FEATURE_GATES=${var.feature_gates} bash /root/master.sh"]
}
provisioner "local-exec" {
command = "bash scripts/copy-kubeadm-token.sh"
environment = {
SSH_PRIVATE_KEY = var.ssh_private_key
SSH_USERNAME = "root"
SSH_HOST = hcloud_server.master[0].ipv4_address
TARGET = "${path.module}/secrets/"
}
}
}
resource "hcloud_server" "node" {
count = var.node_count
name = "node-${count.index + 1}"
server_type = var.node_type
image = var.node_image
depends_on = [hcloud_server.master]
ssh_keys = [hcloud_ssh_key.k8s_admin.id]
connection {
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "files/10-kubeadm.conf"
destination = "/root/10-kubeadm.conf"
}
provisioner "file" {
source = "scripts/bootstrap.sh"
destination = "/root/bootstrap.sh"
}
provisioner "remote-exec" {
inline = ["DOCKER_VERSION=${var.docker_version} KUBERNETES_VERSION=${var.kubernetes_version} bash /root/bootstrap.sh"]
}
provisioner "file" {
source = "${path.module}/secrets/kubeadm_join"
destination = "/tmp/kubeadm_join"
connection {
host = self.ipv4_address
type = "ssh"
user = "root"
private_key = file(var.ssh_private_key)
}
}
provisioner "file" {
source = "scripts/node.sh"
destination = "/root/node.sh"
}
provisioner "remote-exec" {
inline = ["bash /root/node.sh"]
}
}