Skip to content
Latchkey

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.

packer
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

  1. Add a packer init step against the template directory.
  2. Run it before packer validate and packer build.
  3. Confirm the plugin resolves against your required_plugins block.
.github/workflows/build.yml
- 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.

.github/workflows/build.yml
- uses: actions/cache@v4
  with:
    path: ~/.config/packer/plugins
    key: packer-plugins-${{ hashFiles('**/*.pkr.hcl') }}

How to prevent it

  • Always run packer init before build in CI, not only locally.
  • Cache the plugin directory keyed on your template files.
  • Keep required_plugins version constraints pinned so init is reproducible.

Frequently asked questions

What causes ""Failed to initialize""?
The template declares required_plugins, but the CI job jumped straight to packer build. A fresh runner has no plugins cached, so initialization fails.
How do I fix "Failed to initialize"?
Run packer init before build

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card