Build a hardened golden machine image with Packer
A Packer HCL2 template, unattended install config, and pipeline plan for reproducible, hardened VM or cloud images.
The prompt
Help me build a reproducible "golden" machine image with HashiCorp Packer.
Target platforms: [e.g. AWS AMI, Azure, GCP, VMware vSphere, Proxmox]
Base OS and version: [e.g. Ubuntu 24.04, RHEL 9, Windows Server 2022]
Install method: [cloud base image / ISO with unattended install: autoinstall, preseed, Kickstart, or Autounattend.xml]
What the image must include: [packages, agents, users, config]
Hardening standard: [e.g. CIS Level 1, internal baseline, none yet]
Provisioner preference: [shell, PowerShell, Ansible]
Day-0 customization: [cloud-init / cloudbase-init needs]
Build pipeline: [where builds run, e.g. GitHub Actions, GitLab CI, Jenkins]
Produce:
1. A Packer HCL2 template split into sensible files (plugins block with pinned versions, variables with descriptions, sources, build).
2. The unattended install file for my OS, if building from ISO.
3. Provisioning steps in order: updates, packages, hardening, cleanup (remove SSH host keys, machine-id, logs, cloud-init state, temporary credentials) so every instance boots unique.
4. Secrets handling: no passwords or keys in the template; use environment variables or a secrets manager.
5. Validation: packer validate, a smoke test of the built image, and how to tag images with version, date, and source commit.
6. A CI pipeline outline for scheduled rebuilds and image retirement.
Point out common failure points (boot command timing, WinRM/SSH communicator timeouts, cloud-init running twice). Mark any plugin option you are unsure of as [VERIFY IN PLUGIN DOCS].
Highlighted [brackets] are blanks to replace with your own details.
Fill in the blanks and use this promptMore Software Development prompts
What to fill in
- e.g. AWS AMI, Azure, GCP, VMware vSphere, Proxmox
- e.g. Ubuntu 24.04, RHEL 9, Windows Server 2022
- packages, agents, users, config
- e.g. CIS Level 1, internal baseline, none yet
- shell, PowerShell, Ansible
- cloud-init / cloudbase-init needs
- where builds run, e.g. GitHub Actions, GitLab CI, Jenkins
- VERIFY IN PLUGIN DOCS
How this prompt is built
This prompt follows the Few-Shot structure (Few-shot prompting). A few-shot prompt includes one or more worked examples of the input and the output you want, so the model can copy the pattern instead of guessing it.
Related prompts
- Plan a touchscreen UI for an ESP32 or other microcontrollerA memory-aware screen design, library choice, and code structure for a display-based embedded project.
- Restyle a UI component to match a reference designRefactor a component's markup, styles, and accessibility to match a design-system reference while keeping its props, state, and logic intact.
- Diagnose slow launches and API cold starts in my mobile appA codebase-specific diagnosis of startup time, serverless cold starts, and network waste, with fixes ranked by impact on perceived speed.
- Plan the architecture of a Unity game projectA Unity-specific architecture plan: folder and assembly structure, data with ScriptableObjects, scene flow, and system boundaries with C# signatures.