Packer "Failed to initialize" from packer init in CI
Packer 1.7 and later moved builders and provisioners into separately installed plugins. When a template lists required_plugins, packer build fails until packer init has downloaded them into the runner.
What this error means
packer build stops with "Error: Failed to initialize" or a message pointing you to run packer init, because the template references a plugin the runner does not have.
Error: Failed to initialize
Error: 1 error occurred:
* Failed to initialize build: required plugin "github.com/hashicorp/amazon" is not installed. Run "packer init".Common causes
packer init never ran on the ephemeral runner
The template declares required_plugins, but the CI job jumped straight to packer build. A fresh runner has no plugins cached, so initialization fails.
The plugin cache is not persisted between jobs
Even if a prior job ran init, a new ephemeral runner starts empty. Without a step that runs init or restores a cache, plugins are missing again.
How to fix it
Run packer init before build
- Add a
packer initstep against the template directory. - Run it before
packer validateandpacker build. - Confirm the plugin resolves against your
required_pluginsblock.
- run: packer init .
- run: packer validate .
- run: packer build .Cache the plugin directory across runs
Persist the Packer plugin path so repeat jobs skip re-downloading and init is fast.
- uses: actions/cache@v4
with:
path: ~/.config/packer/plugins
key: packer-plugins-${{ hashFiles('**/*.pkr.hcl') }}How to prevent it
- Always run
packer initbefore build in CI, not only locally. - Cache the plugin directory keyed on your template files.
- Keep
required_pluginsversion constraints pinned so init is reproducible.