Deep Dive of the Day Building VM templates for vSphere 9 with Packer: content libraries, firmware and the options that trip people up
Golden images are the quiet foundation of most VCF automation: VCF Automation blueprints, Terraform vsphere_virtual_machine clones and VKS-adjacent VMs all start from a template somebody built. Packer's vsphere plugin, now maintained under VMware by Broadcom, is the usual way to build them as code. It has two builders: vsphere-iso, which creates a VM from scratch and installs the OS from an ISO, and vsphere-clone, which starts from an existing template, OVF or content library item. The current release is v2.5.1 (3 Nov), a maintenance release (PR #862), so the option set below is stable.
The first decision is where the result lives. By default you get an ordinary VM, and convert_to_template = true turns it into a vCenter template. If you want it in a content library instead, set content_library_destination, and here's the first trap: that block requires convert_to_template = false, because the docs say a VM converted to a template can't then be imported into a library. Inside the block, library must be a local library, and ovf decides the item type: false (the default) gives you a VM template (VMTX), true an OVF template.
The two item types behave differently, and it matters for your pipeline. An OVF template keeps the vm_name as its item name and is updated in place on each build. A VM template defaults to vm_name plus a timestamp and is always a new item; the plugin docs are explicit that VM templates can't update existing library items in place, and overwrite on a VM template deletes the old item before creating the new one. Per the vSphere 9.1 docs, choosing a VM template also creates an identical template in the vCenter inventory, whereas an OVF template doesn't. William Lam's VMTX write-up is a good summary of why VM templates are worth it: subscription management from the publisher side, per-item permissions and check-in/check-out, at the cost of needing linked vCenters with trust for subscriptions, and templates built on a newer release generally won't deploy on an older one.
Firmware and security devices are the next set of choices. firmware takes bios, efi or efi-secure, and for modern Windows and Linux builds efi-secure is the sensible default. vTPM = true adds a virtual TPM, but a VM with a vTPM can't be exported as OVF/OVA or imported as an OVF template. If you need OVF output, remove_vtpm (added in v2.5.0) strips the device after shutdown; a content library VM template, on the other hand, can keep it. Turning on vbs_enabled for Virtualisation-based Security needs efi-secure, vvtd_enabled and NestedHV all set. And on clones, firmware isn't inferred from the source template, so set it explicitly.
Storage settings deserve a careful read. disk_controller_type is a list (lsilogic by default, plus pvscsi, nvme, lsilogic-sas, sata and others), and each storage block takes disk_size in MiB, disk_thin_provisioned (which defaults to false, so set it if you want thin disks) and disk_controller_index. storage_policy must already exist in vCenter; with no datastore named, each policy chooses a compliant datastore, which is handy on vSAN ESA. On vsphere-clone, disk_controller_unit lets you place an added disk at an exact address such as scsi0:1 or nvme0:0, with PVSCSI unit 7 reserved, and an address on a controller type the template lacks fails at packer validate. A fix that rejects overflowing unit numbers is merged for the next release.
Getting the installer its answer file is where most failed builds start. If you set http_directory or http_content, Packer runs a small HTTP server and your boot_command can reference it with {{ .HTTPIP }} and {{ .HTTPPort }}. The port is picked between 8000 and 9000 unless you pin http_port_min and http_port_max to the same value, which is what you want when a firewall sits between the build VM's network and your Packer host. http_ip is only used if http_bind_address and http_interface are unset. The alternative is cd_content or cd_files, which build a small ISO (labelled cidata in the examples) and attach it, so the guest never needs to reach Packer over the network; it needs xorriso, mkisofs, hdiutil or oscdimg on the build host.
Cleaning up matters before you publish. remove_cdrom removes the CD drives after the build (unless reattach_cdroms is above zero, in which case it keeps empty drives instead), and remove_network_adapter strips the NICs if your deployment process adds its own. Packer waits for an IP via VMware Tools or open-vm-tools, so the guest must have them installed and running early; ip_wait_timeout defaults to 30 minutes, and ip_wait_address lets you filter out link-local or wrong-subnet addresses. tools_upgrade_policy and tools_sync_time set the matching VM options, and vm_version defaults to the newest hardware version the host supports, so pin it if the template must deploy to older clusters.
Permissions are easy to under-scope. The plugin docs recommend a dedicated service account with a custom role cloned from Read-Only and assigned as a global permission propagated to children, because content library rights follow global permissions. The library privileges it names are Add library item, Update library item and download sessions, and the vSphere 9.1 docs add datastore space allocation, cloning or creating templates and viewing storage policies. In a VCF fleet, it's tidy to give that account access to the workload domain vCenters only, so builds can never land in the management domain.
For nested labs, a few things follow directly from the above. If your nested build network has no route back to the Packer host, cd_content sidesteps the HTTP server entirely. Pinning the HTTP port makes firewall rules on a lab router much easier. Keep vm_version in mind if your lab runs a newer ESX than your physical host, because a template built at the newest hardware version won't power on further down. And if you want somewhere to start, VMware's packer-examples-for-vsphere project follows the same split we've described: Linux answer files over HTTP and Windows over a CD image, with content library output on by default. Its upcoming release adds vSphere 9.0 to its tested platforms.
The practical recipe, then: decide early between OVF and VM template items, because it shapes versioning and vTPM handling; build with efi-secure, thin disks and an explicit hardware version; deliver answer files on a CD when the network is uncertain; strip the build-time devices; and run Packer as a narrowly scoped service account. Do that and your templates become something you can rebuild every Patch Tuesday without anyone having to log in to the console.
Based on Packer vsphere-iso builder (HashiCorp) Official Packer vsphere-clone builder docs Official Clone a VM or template to a content library template (vSphere 9.1) Official packer-plugin-vsphere v2.5.1 release PR Official packer-examples-for-vsphere release notes Official Benefits of VM templates in content library (William Lam)