resource "proxmox_virtual_environment_vm" "hive_node" { count = var.node_count name = "${var.cluster_name}-${count.index + 1}" description = "Managed by Terraform" tags = ["terraform", "spinifex", var.cluster_name] node_name = var.nodes[count.index % length(var.nodes)].name initialization { datastore_id = "local" vendor_data_file_id = proxmox_virtual_environment_file.cloud_config[count.index].id user_account { username = "tf-user" keys = [trimspace(data.local_file.ssh_public_key.content)] } # Management ip_config { ipv4 { address = "dhcp" } } # Data/VM ip_config { ipv4 { address = "dhcp" } } } cpu { cores = var.cpu_cores type = "host" } memory { dedicated = var.memory_mb } agent { enabled = true } network_device { bridge = var.nodes[count.index % length(var.nodes)].bridge } network_device { bridge = var.nodes[count.index % length(var.nodes)].bridge } # Clone from template if the target node has template_vmid set, otherwise boot from cloud image. dynamic "clone" { for_each = var.nodes[count.index % length(var.nodes)].template_vmid != null ? [1] : [] content { vm_id = var.nodes[count.index % length(var.nodes)].template_vmid full = true } } dynamic "disk" { for_each = var.nodes[count.index % length(var.nodes)].template_vmid == null ? [1] : [] content { file_id = var.os_image datastore_id = var.nodes[count.index % length(var.nodes)].datastore_id interface = "virtio0" iothread = true discard = "on" size = var.disk_size_gb } } }