-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
101 lines (84 loc) · 2.23 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
provider "libvirt" {
uri = "qemu:///system"
}
resource "libvirt_pool" "cluster" {
name = "default"
type = "dir"
path = var.pool_path
}
resource "libvirt_network" "default" {
name = "default"
addresses = var.networks
domain = local.domainname
bridge = "virbr0"
dns {
hosts {
ip = local.controleplane_ips[0]
hostname = "cluster-endpoint"
}
dynamic "hosts" {
for_each = local.controleplane_ips
content {
ip = hosts.value
hostname = format("controlplane-%02d", hosts.key + 1)
}
}
}
}
module "workers" {
source = "./modules/vm"
autostart = false
vm_hostname_prefix = "worker"
vm_count = var.worker_count
memory = "1024"
vcpu = 1
system_volume = 10
time_zone = "CET"
os_img_url = var.os_img_url
pool = libvirt_pool.cluster.name
dhcp = true
# vm_domain = local.domainname
# ip_address = local.controleplane_ips
# ip_gateway = cidrhost(local.controleplane_network, 1)
# ip_nameserver = cidrhost(local.controleplane_network, 1)
bridge = libvirt_network.default.bridge
http_proxy = var.http_proxy
ssh_admin = var.ssh_admin
ssh_private_key = var.ssh_private_key
ssh_keys = [
file("${var.ssh_private_key}.pub"),
]
runcmd = [
"install-kubeadm.sh ${local.cluster_endpoint}:6443 ${local.kubeadm_token} --discovery-token-unsafe-skip-ca-verification"
]
}
resource "ssh_resource" "workers_destroy" {
count = var.worker_count
host = local.cluster_endpoint_ip
user = var.ssh_admin
private_key = var.ssh_private_key
when = "destroy"
timeout = "30s"
commands = [
"sudo /usr/local/bin/remove-node.sh ${module.workers.name[count.index]}"
]
}
resource "ssh_resource" "sample_work" {
host = local.cluster_endpoint_ip
user = var.ssh_admin
private_key = var.ssh_private_key
timeout = "11s"
file {
source = "sample_work.yaml"
destination = "/tmp/sample_work.yaml"
}
commands = [
"sudo KUBECONFIG=/etc/kubernetes/admin.conf kubectl apply -f /tmp/sample_work.yaml"
]
}
output "worker" {
value = module.workers
}
output "run" {
value = ssh_resource.sample_work.result
}