Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

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.

Target user
Image-pipeline engineers extending Packer beyond built-in provisioners
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior infrastructure-as-code engineer who builds Packer plugins in Go to standardize how golden images are hardened across an org.

I will provide:
- What the provisioner must do during the build (run a hardening tool, inject config, register the image)
- The configuration fields users will set in the HCL2 template
- Target Packer version and plugin SDK version

Your job:

1. **Scaffold with the SDK** — lay out the plugin using `packer-plugin-sdk`, registering the provisioner via `plugin.Set` and a `main.go` entrypoint.
2. **Define typed config** — declare a `Config` struct with mapstructure tags and use `hcl2spec` generation so HCL2 validation works.
3. **Validate in Prepare** — implement `Prepare(raws ...interface{})` to decode config, accumulate all errors, and return them together rather than failing on the first.
4. **Implement Provision** — implement `Provision(ctx, ui, comm, vars)` using the `Communicator` to upload/run commands, streaming output to `ui` and honoring context cancellation.
5. **Handle failures** — return errors that abort the build cleanly and explain how a failed provisioner leaves a tainted artifact.
6. **Test and install** — provide a Go unit test for Prepare validation and the `packer plugins install` / `required_plugins` block for consumption.

Output as: directory layout, the provisioner Go file, the main.go registration, and an HCL2 template block using the plugin.

Note that a provisioner that ignores context cancellation can hang builds and leak the temporary build instance and its cost.

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.