-
Notifications
You must be signed in to change notification settings - Fork 45
/
worker_nodes.tf
115 lines (92 loc) · 2.39 KB
/
worker_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
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
107
108
109
110
111
112
113
114
115
resource "macaddress" "k3s-workers" {
for_each = local.mapped_worker_nodes
}
locals {
listed_worker_nodes = flatten([
for pool in var.node_pools :
[
for i in range(pool.size) :
merge(defaults(pool, {
cores = 2
sockets = 1
memory = 4096
storage_type = "scsi"
storage_id = "local-lvm"
disk_size = "20G"
user = "k3s"
template = var.node_template
network_bridge = "vmbr0"
network_tag = -1
}), {
i = i
ip = cidrhost(pool.subnet, i)
})
]
])
mapped_worker_nodes = {
for node in local.listed_worker_nodes : "${node.name}-${node.i}" => node
}
}
resource "proxmox_vm_qemu" "k3s-worker" {
depends_on = [
proxmox_vm_qemu.k3s-support,
proxmox_vm_qemu.k3s-master,
]
for_each = local.mapped_worker_nodes
target_node = var.proxmox_node
name = "${var.cluster_name}-${each.key}"
clone = each.value.template
pool = var.proxmox_resource_pool
# cores = 2
cores = each.value.cores
sockets = each.value.sockets
memory = each.value.memory
agent = 1
disk {
type = each.value.storage_type
storage = each.value.storage_id
size = each.value.disk_size
}
network {
bridge = each.value.network_bridge
firewall = true
link_down = false
macaddr = upper(macaddress.k3s-workers[each.key].address)
model = "virtio"
queues = 0
rate = 0
tag = each.value.network_tag
}
lifecycle {
ignore_changes = [
ciuser,
sshkeys,
disk,
network
]
}
os_type = "cloud-init"
ciuser = each.value.user
ipconfig0 = "ip=${each.value.ip}/${local.lan_subnet_cidr_bitnum},gw=${var.network_gateway}"
sshkeys = file(var.authorized_keys_file)
nameserver = var.nameserver
connection {
type = "ssh"
user = each.value.user
host = each.value.ip
}
provisioner "remote-exec" {
inline = [
templatefile("${path.module}/scripts/install-k3s-server.sh.tftpl", {
mode = "agent"
tokens = [random_password.k3s-server-token.result]
alt_names = []
disable = []
server_hosts = ["https://${local.support_node_ip}:6443"]
node_taints = each.value.taints
datastores = []
http_proxy = var.http_proxy
})
]
}
}