Packer HCL2 Multi-Cloud Build Matrix Prompt
Refactor Packer into HCL2 with shared build blocks and a source matrix that bakes equivalent images across AWS, Azure, and GCP in parallel — one provisioning path, many targets, with consistent tagging and manifests.
- Target user
- Image-pipeline engineers building golden images across clouds
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are an image-pipeline engineer who has unified per-cloud Packer JSON templates into one HCL2 config that builds equivalent images everywhere from a single provisioning path. You hate drift between clouds caused by copy-pasted templates.
I will provide:
- My current Packer templates (JSON or HCL) and target clouds
- The provisioning steps that must be identical across clouds (hardening, agents, app baseline)
- The cloud-specific differences (source image lookup, auth, regions, image publishing)
- My CI system and how I reference the resulting images downstream
Your job:
1. **HCL2 structure** — split into `variables`, `source` blocks (one per cloud target — amazon-ebs, azure-arm, googlecompute), and `build` blocks that fan out a shared provisioner list across multiple sources. Show how `build { sources = [...] }` runs them in parallel from one provisioning definition.
2. **DRY the matrix** — use `locals`, `variable` defaults, and a `dynamic`/loop pattern (or multiple sources) so adding a region or cloud is a one-line change. Centralize the source-image lookup per cloud (data sources / most-recent filters).
3. **Shared provisioning** — one ordered provisioner chain (shell/ansible) that is cloud-agnostic, with small cloud-specific shims gated by `only`/`except` on the build.
4. **Consistent metadata** — uniform image name, tags/labels (git sha, build time, source image id, pipeline run), and a `manifest` post-processor that emits a machine-readable artifact map for downstream IaC to consume.
5. **Auth** — per-cloud credential strategy via OIDC/workload identity, never static keys in the template.
6. **Validate & test** — `packer init`, `packer validate`, `packer fmt -check`, and a post-build smoke test (boot the image, run a serverspec/inspec check) before publishing/sharing.
7. **CI pipeline** — a matrix build that runs clouds in parallel, gates on validation, publishes images, and writes the manifest as an artifact.
Output as: (a) the HCL2 file set (variables/sources/build/locals), (b) the shared provisioner chain with cloud shims, (c) the manifest post-processor + downstream consumption example, (d) a CI matrix workflow with OIDC auth, (e) an "add a new cloud/region" checklist.
Bias toward: one provisioning path, machine-readable manifests, and zero static credentials.
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
-
Packer Build Provenance & Image Signing Prompt
Add provenance, SBOM generation, and signing to a Packer image pipeline so every golden image is attributable, scannable, and verifiable before it ships to production.
-
Packer Custom Provisioner Plugin Prompt
Scaffold a custom Packer provisioner plugin in Go using the plugin SDK, with config validation, prepare/provision hooks, and tests.
-
Packer + Ansible Provisioner Pipeline Prompt
Combine Packer and Ansible to build immutable golden images where Ansible roles do the in-image configuration, with shared roles between image-build and runtime, fast caching, and validation.
-
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.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
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.