-
Notifications
You must be signed in to change notification settings - Fork 9
/
k8s-controlplane.tf
95 lines (83 loc) · 2.09 KB
/
k8s-controlplane.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
resource "proxmox_vm_qemu" "k8s_controlplane" {
for_each = local.k8s_controlplane
name = each.key
target_node = each.value.target_node
desc = "Kubernetes control plane"
clone = local.k8s_common.clone_k8s
vmid = each.value.vmid
cpu = "kvm64"
sockets = 1
cores = each.value.cores
memory = each.value.memory
os_type = "cloud-init"
qemu_os = "l26"
agent = 1
scsihw = "virtio-scsi-pci"
onboot = true
ssh_forward_ip = each.value.ip
ipconfig0 = "ip=${each.value.ip}/24,gw=${local.k8s_common.gw}"
sshkeys = var.ssh_pub_keys
disks {
ide {
ide2 {
cloudinit {
storage = "local-lvm"
}
}
}
scsi {
scsi0 {
disk {
storage = each.value.storage_clone_to
size = each.value.disk
discard = true
emulatessd = true
replicate = true
}
}
}
}
network {
model = "virtio"
bridge = "vmbr1"
tag = 13
}
vga {
memory = 0
type = "serial0"
}
serial {
id = 0
type = "socket"
}
lifecycle {
ignore_changes = [
clone,
pool,
ciuser,
disks[0].scsi[0].scsi0[0].disk[0].storage,
]
}
provisioner "remote-exec" {
inline = ["while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 1; done"]
connection {
host = self.default_ipv4_address
user = local.vm_user
timeout = "120s"
private_key = file("~/.ssh/id_rsa")
}
}
# Move disks from shared to local storage
provisioner "local-exec" {
command = <<EOT
for disk in ${local.k8s_common.ci_disk} ${local.k8s_common.boot_disk}; do
curl --silent --insecure \
${var.proxmox_url}/nodes/${each.value.target_node}/qemu/${each.value.vmid}/move_disk \
--header "Authorization: PVEAPIToken=${var.proxmox_username}=${var.proxmox_token}" \
--data-urlencode disk="$disk" \
--data-urlencode storage="${local.k8s_common.storage_move_to}" \
--data-urlencode delete=1
done
EOT
}
}