Files
zavrsni-rad-templates/ws2022/main.pkr.hcl
2026-03-07 17:59:58 +01:00

117 lines
3.1 KiB
HCL

packer {
required_plugins {
proxmox = {
version = "~> 1"
source = "github.com/hashicorp/proxmox"
}
windows-update = {
version = "0.17.3"
source = "github.com/rgl/windows-update"
}
}
}
# -----------------------------------------------------------------------------
# Source: Proxmox VM definition
# -----------------------------------------------------------------------------
source "proxmox-iso" "ws2022" {
# Proxmox connection
proxmox_url = var.proxmox_url
username = var.proxmox_token_id
token = var.proxmox_token_secret
node = var.proxmox_node
insecure_skip_tls_verify = var.proxmox_skip_tls
# VM metadata
vm_name = var.vm_name
template_description = "Windows Server 2022 Datacenter - Cloudbase-Init - Built ${formatdate("YYYY-MM-DD", timestamp())}"
vm_id = var.vm_id
# Hardware
os = "win11"
memory = var.vm_memory
cores = var.vm_cores
cpu_type = "x86-64-v3"
machine = "pc-q35-10.1"
bios = "ovmf"
qemu_agent = true
efi_config {
efi_storage_pool = var.storage_pool
efi_type = "4m"
pre_enrolled_keys = true
}
scsi_controller = "virtio-scsi-single"
disks {
type = "scsi"
disk_size = var.disk_size
storage_pool = var.storage_pool
format = "raw"
}
network_adapters {
model = "virtio"
bridge = var.network_bridge
firewall = false
}
# Windows Server 2022 ISO
iso_file = var.iso_file
# --- KEY: dynamically generated ISO with templated Autounattend.xml ---
additional_iso_files {
cd_content = {
"Autounattend.xml" = templatefile("answer_files/Autounattend.xml.pkrtpl", {
admin_password = var.admin_password
image_index = var.image_index
product_key = var.product_key
locale = var.locale
timezone = var.timezone
virtio_drive = var.virtio_drive_letter
os_partition_mb = var.os_partition_mb
})
}
cd_label = "OEMDRV"
iso_storage_pool = var.iso_storage_pool
unmount = true
}
# VirtIO drivers ISO
additional_iso_files {
device = "sata1"
iso_file = var.virtio_iso
iso_storage_pool = var.iso_storage_pool
unmount = true
}
# WinRM communicator - password injected from variable
communicator = "winrm"
winrm_username = "Administrator"
winrm_password = var.admin_password
winrm_timeout = "90m"
winrm_insecure = true
winrm_use_ssl = false
boot_wait = "5s"
boot_command = ["<spacebar><spacebar><spacebar>"]
}
# -----------------------------------------------------------------------------
# Build: provisioning steps
# -----------------------------------------------------------------------------
build {
sources = ["source.proxmox-iso.ws2022"]
# Install and configure Cloudbase-Init
provisioner "powershell" {
script = "scripts/install-cloudbase-init.ps1"
}
# Sysprep with Cloudbase-Init's unattend
provisioner "powershell" {
script = "scripts/sysprep.ps1"
}
}