packer init: Usage & Common CI Errors
Install the plugins an HCL2 Packer template requires - before you build.
packer init downloads and installs the plugins declared in a template’s required_plugins block. It is the first command for HCL2 templates and the one CI forgets before build.
What it does
packer init reads the required_plugins block in your .pkr.hcl files and installs matching plugin binaries (e.g. the amazon, docker, googlecompute plugins) into Packer’s plugin directory. It only applies to HCL2 templates; legacy JSON templates have no init step.
Common usage
# Install plugins for the template(s) in this directory
packer init .
# Force re-install / upgrade within constraints
packer init -upgrade .Common error in CI: build run before init
A bare packer build in CI fails with "Error: Failed to initialize build ... To install the missing plugins, run: packer init". HCL2 templates do not auto-install plugins at build time. Fix: run packer init . as a step before packer build, and pin each plugin’s version in required_plugins so a new release cannot change behavior mid-pipeline. Cache the plugin directory between runs to avoid re-downloading.
Key options
| Option | Purpose |
|---|---|
| PATH | Template file or directory to init |
| -upgrade | Upgrade plugins within constraints |
| -force | Reinstall plugins |