Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

Packer Golden Image Pipeline Prompt

Design a Packer build that produces hardened, reproducible golden machine images across clouds — provisioners, versioning, CVE scanning, and a bake-vs-boot decision framework.

Target user
Infrastructure engineers building immutable VM/AMI images
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure engineer who has run golden-image pipelines that bake thousands of immutable images a month with full provenance.

I will provide:
- Target platforms (AWS AMI, Azure managed image, GCP image, vSphere, QEMU)
- Base OS and hardening requirements (CIS level, FIPS, org baseline)
- What goes in the image vs configured at boot
- CI system and where images are consumed (ASG launch templates, MIGs, node pools)

Your job:

1. **Bake vs boot** — give me a decision framework: what belongs IN the image (agents, hardening, base packages, runtime) vs what should be injected at boot (secrets, instance config, app version). Default to baking the slow/stable layer, booting the fast/changing layer.

2. **Packer template** — HCL2 `packer {}` block with required plugins pinned, `source` blocks per platform, and a shared `build` block. Show variables for region, base AMI lookup (via `data` source / source_ami_filter), and instance type.

3. **Provisioners** — order them: OS update → hardening (CIS via Ansible or shell) → install agents → app runtime → cleanup. Use the `ansible` or `shell` provisioner; explain why a `file` + `shell` combo beats inline heredocs for anything non-trivial.

4. **Reproducibility** — pin the base image by ID per region (not `latest`), pin package versions where it matters, and stamp the image with build metadata tags (git SHA, pipeline ID, build date, source AMI).

5. **Security** — run a CVE scan (Trivy/Grype) against the built image and FAIL the build on criticals; remove SSH host keys, cloud-init logs, bash history, and the provisioning user before finalizing.

6. **Versioning & promotion** — semantic image naming, a manifest post-processor that records the image ID, and how to promote dev → prod images by re-tagging rather than rebuilding.

7. **Cost & cleanup** — deregister old images + delete orphaned snapshots on a retention policy.

Output as: (a) full HCL2 template(s), (b) a hardening provisioner outline, (c) a CI pipeline with the Trivy gate, (d) an image-promotion + retention policy, (e) the top 3 reproducibility traps and fixes.

Bias toward: pinned everything, immutable + disposable images, and provenance you can audit.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.