-
Notifications
You must be signed in to change notification settings - Fork 10
/
master.tf
executable file
·75 lines (61 loc) · 1.89 KB
/
master.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
resource "hcloud_server" "master" {
name = var.master_name
image = data.hcloud_image.k8s_image.id
server_type = var.master_server_type
location = var.master_location
ssh_keys = [hcloud_ssh_key.default.name]
provisioner "file" {
source = "scripts/run-master.sh"
destination = "/tmp/run-master.sh"
connection {
type = "ssh"
user = "root"
host = self.ipv4_address
private_key = file("~/.ssh/id_rsa")
}
}
}
resource "hcloud_floating_ip" "master" {
type = "ipv4"
server_id = hcloud_server.master.id
}
resource "hcloud_floating_ip_assignment" "master" {
floating_ip_id = hcloud_floating_ip.master.id
server_id = hcloud_server.master.id
}
resource "hcloud_server_network" "srvnetwork" {
server_id = hcloud_server.master.id
network_id = hcloud_network.mynet.id
ip = "10.0.1.5"
}
resource "null_resource" "k8s_master" {
# Changes to any instance of the cluster requires re-provisioning
triggers = {
cluster_instance_ids = hcloud_server.master.name
}
connection {
type = "ssh"
host = hcloud_server.master.ipv4_address
user = "root"
private_key = file("~/.ssh/id_rsa")
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/run-master.sh",
"/tmp/run-master.sh"
]
}
provisioner "local-exec" {
command = "./scripts/kubectl-conf.sh ${terraform.workspace} ${hcloud_server.master.ipv4_address} ${hcloud_server_network.srvnetwork.ip} ~/.ssh/id_rsa"
on_failure = continue
}
}
data "external" "kubeadm_join" {
program = ["./scripts/kubeadm-token.sh"]
query = {
host = hcloud_server.master.ipv4_address
key = "~/.ssh/id_rsa" # private key
}
# depends_on = [hcloud_server.master]
depends_on = [null_resource.k8s_master]
}