resource "libvirt_domain" "cs10-base" { count = var.guest_count name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}" memory = var.guest_memory memory_unit = "MiB" vcpu = var.guest_vcpu running = true autostart = true type = "kvm" os = { type = "hvm" arch = "x86_64" machine = "q35" firmware = "efi" loader_path = "/usr/share/edk2/ovmf/OVMF_CODE_4M.secboot.qcow2" loader_readonly = true loader_secure = true loader_type = "pflash" nvram = { path = "/var/lib/libvirt/qemu/nvram/${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}_VARS.qcow2" template = "/usr/share/edk2/ovmf/OVMF_VARS_4M.secboot.qcow2" format = "qcow2" } } cpu = { mode = "host-passthrough" } features = { acpi = true apic = {} } devices = { disks = [ { type = "volume" driver = { type = "qcow2" } source = { volume = { pool = var.pool_name volume = libvirt_volume.cs10-base[count.index].name } } target = { dev = "vda" bus = "virtio" } }, { type = "volume" device = "cdrom" readonly = true driver = { type = "raw" } source = { volume = { pool = var.pool_name volume = libvirt_cloudinit_disk.cs10-cloudinit[count.index].name } } target = { dev = "sda" bus = "sata" } } ] interfaces = [ { type = "network" model = { type = "virtio" } source = { network = { network = "default" } } } ] consoles = [ { type = "pty" target_type = "virtio" target_port = "1" } ] video = { type = "virtio" } } } resource "libvirt_volume" "cs10-base" { count = var.guest_count name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-system.qcow2" pool = var.pool_name capacity = 32212254720 target = { format = { type = "qcow2" } } create = { content = { url = "file://${var.base_image_path}" } } } resource "libvirt_cloudinit_disk" "cs10-cloudinit" { count = var.guest_count name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-cloudinit.iso" user_data = templatefile("templates/cloudinit.cfg.tftpl", { root_password = var.root_password hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}" }) meta_data = yamlencode({ instance-id = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}" local-hostname = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}" }) } resource "libvirt_volume" "cloudinit" { count = var.guest_count name = "${var.guest_base_name}-${format("%02d", count.index)}.${var.domain}-cloudinit.iso" pool = var.pool_name target = { format = { type = "iso" } } create = { content = { url = libvirt_cloudinit_disk.cs10-cloudinit[count.index].path } } }