resource "libvirt_pool" "this" { count = var.create_root_storage_pool ? 1 : 0 name = local.root_storage_pool type = "dir" path = "/vmstore/${var.name}" } resource "libvirt_volume" "this" { name = local.root_storage_volume_name pool = local.root_storage_pool size = var.root_storage_volume_size_gb * 1024 * 1024 * 1024 base_volume_name = var.base_image_volume base_volume_pool = var.base_image_pool } resource "macaddress" "this" { } module "ipam" { source = "git@git.thomasklein.me:thomasklein/terraform-modules//lawndale-vm-ipam" id = var.id name = var.name interface = var.interface } resource "libvirt_domain" "this" { name = "${var.id}-${var.name}" description = var.description vcpu = var.vcpu memory = var.memory_mb autostart = var.autostart cloudinit = libvirt_cloudinit_disk.this.id firmware = var.uefi ? "/usr/share/edk2-ovmf/OVMF_CODE.fd" : null machine = var.machine network_interface { bridge = module.ipam.lawndale_interface mac = macaddress.this.address } dynamic "network_interface" { for_each = var.extra_interfaces content { bridge = network_interface.value.bridge mac = network_interface.value.mac } } disk { volume_id = libvirt_volume.this.id scsi = true } # video { type = "virtio" } # graphics {} console { type = "pty" target_port = 0 target_type = "serial" } qemu_agent = true dynamic "filesystem" { for_each = var.filesystems content { source = filesystem.value.source target = filesystem.value.target readonly = filesystem.value.readonly accessmode = filesystem.value.accessmode } } dynamic "xml" { for_each = var.xslt == null ? [] : [var.xslt] content { xslt = xml.value } } lifecycle { ignore_changes = [nvram, disk[0].scsi] } } resource "libvirt_cloudinit_disk" "this" { name = "${var.id}-${var.name}-cloudinit" pool = local.root_storage_pool meta_data = local.meta_data network_config = local.network_config user_data = var.user_data } locals { default_network_config = { version = 2 ethernets = { eth = { match = { macaddress = macaddress.this.address } "set-name" = "eth" addresses = [ "${module.ipam.ip_address}/${module.ipam.cidr}" ] gateway4 = module.ipam.gateway nameservers = { search = module.ipam.search_domains addresses = [ module.ipam.nameserver ] } } } } default_meta_data = <