-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
vm-control-plane.tf
99 lines (85 loc) · 2.63 KB
/
vm-control-plane.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
locals {
talos_iso_image_location = "${var.talos_iso_destination_storage_pool}:iso/${replace(var.talos_iso_destination_filename, "%", var.talos_version)}"
//noinspection HILUnresolvedReference
vm_control_planes = flatten([
for name, host in var.proxmox_servers : [
for i in range(host.control_planes_count) : name
]
])
vm_control_planes_count = length(local.vm_control_planes)
}
# this keeps bitching about the file already exists... i know, just skip it then
#
# resource "proxmox_virtual_environment_file" "talos-iso" {
# content_type = "iso"
# datastore_id = var.talos_iso_destination_storage_pool
# node_name = var.talos_iso_destination_server != "" ? var.talos_iso_destination_server : keys(var.proxmox_servers)[0]
# overwrite = false
#
# source_file {
# path = replace(var.talos_iso_download_url, "%", var.talos_version)
# file_name = replace(var.talos_iso_destination_filename, "%", var.talos_version)
# }
# }
resource "macaddress" "talos-control-plane" {
count = length(local.vm_control_planes)
}
resource "proxmox_virtual_environment_vm" "talos-control-plane" {
depends_on = [
# proxmox_virtual_environment_file.talos-iso,
macaddress.talos-control-plane
]
for_each = {
for i, x in local.vm_control_planes : i => x
}
name = "${var.control_plane_name_prefix}-${each.key + 1}"
vm_id = each.key + var.control_plane_first_id
node_name = each.value
on_boot = true
scsi_hardware = "virtio-scsi-pci"
agent {
enabled = true
}
initialization {
ip_config {
ipv4 {
address = "${cidrhost(var.network_cidr, each.key + var.control_plane_first_ip)}/${split("/", var.network_cidr)[1]}"
gateway = var.network_gateway
}
}
}
cdrom {
enabled = true
file_id = replace(local.talos_iso_image_location, "%", var.talos_version)
}
cpu {
type = "host"
sockets = 1
cores = var.control_plane_cpu_cores
}
memory {
dedicated = var.control_plane_memory*1024
}
network_device {
enabled = true
model = "virtio"
bridge = var.proxmox_servers[each.value].network_bridge
mac_address = macaddress.talos-control-plane[each.key].address
firewall = false
}
operating_system {
type = "l26" # Linux kernel type
}
disk {
interface = "virtio0"
size = var.control_plane_disk_size
datastore_id = var.proxmox_servers[each.value].disk_storage_pool
file_format = "raw"
cache = "writethrough"
iothread = true
backup = false
}
}
output "talos_control_plane_mac_addrs" {
value = macaddress.talos-control-plane
}