70 lines
1.6 KiB
HCL
70 lines
1.6 KiB
HCL
locals {
|
|
default_ipconfig0 = "ip=dhcp"
|
|
}
|
|
|
|
resource "proxmox_vm_qemu" "vm" {
|
|
for_each = var.vms
|
|
|
|
name = each.value.name
|
|
target_node = var.proxmox_node
|
|
vmid = try(each.value.vmid, null)
|
|
|
|
onboot = true
|
|
agent = 1
|
|
clone = var.template_name
|
|
full_clone = true
|
|
vga {
|
|
type = "serial0"
|
|
}
|
|
|
|
cpu {
|
|
sockets = 1
|
|
cores = each.value.cores
|
|
type = "host"
|
|
}
|
|
memory = each.value.memory_mb
|
|
|
|
scsihw = "virtio-scsi-pci"
|
|
boot = "c"
|
|
bootdisk = "scsi0"
|
|
|
|
serial {
|
|
id = 0
|
|
type = "socket"
|
|
}
|
|
|
|
# Network: bridge vmbr0, optional VLAN tag
|
|
network {
|
|
id = 0
|
|
model = "virtio"
|
|
bridge = "vmbr0"
|
|
tag = try(each.value.vlan_tag, 0)
|
|
}
|
|
|
|
# Cloud-init: user, ssh keys, IP, and custom snippet for qemu-guest-agent
|
|
# Note: Using vendor-data snippet (instead of user-data) allows Proxmox to automatically
|
|
# set the hostname from the VM name. User info is set separately via ciuser/sshkeys.
|
|
# Using 'local' storage for snippets (not ZFS) as ZFS storage doesn't properly support snippet paths
|
|
ciuser = var.cloud_init_user
|
|
sshkeys = var.ssh_authorized_keys
|
|
ipconfig0 = try(each.value.ipconfig0, local.default_ipconfig0)
|
|
cicustom = "vendor=local:snippets/user-data-qemu-agent.yaml"
|
|
|
|
# Disk on ZFS storage
|
|
disk {
|
|
slot = "scsi0"
|
|
type = "disk"
|
|
storage = var.zfs_storage_name
|
|
size = "${each.value.disk_size_gb}G"
|
|
# optional flags like iothread/ssd/discard differ by provider versions; keep minimal
|
|
}
|
|
|
|
# Cloud-init CD-ROM so ipconfig0/sshkeys apply
|
|
disk {
|
|
slot = "ide2"
|
|
type = "cloudinit"
|
|
storage = var.zfs_storage_name
|
|
}
|
|
}
|
|
|
|
|