hashicorp/packer · error
Error interpolating builder '%s': %s
Error message
Error interpolating builder '%s': %s
What it means
During Core initialization (packer/core.go initialize), builder names from the template are rendered through HCL2/interpolation with the core's context. If rendering a builder's Name fails (e.g. an unknown or unresolvable user variable), initialize returns "Error interpolating builder '%s': %s" naming the builder and the interpolation error. Core initialization then aborts before any build runs.
Source
Thrown at packer/core.go:187
func (core *Core) initialize() error {
if err := core.validate(); err != nil {
return err
}
if err := core.init(); err != nil {
return err
}
for _, secret := range core.secrets {
RegisterSecret(secret)
}
// Go through and interpolate all the build names. We should be able
// to do this at this point with the variables.
core.builds = make(map[string]*template.Builder)
for _, b := range core.Template.Builders {
v, err := interpolate.Render(b.Name, core.Context())
if err != nil {
return fmt.Errorf(
"Error interpolating builder '%s': %s",
b.Name, err)
}
core.builds[v] = b
}
return nil
}
func (c *Core) PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics) {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Summary: "Packer plugins currently only works with HCL2 configuration templates",
Detail: "Please manually install plugins with the plugins command or use a HCL2 configuration that will do that for you.",
Severity: hcl.DiagError,
},
}View on GitHub (pinned to eb36e3c3e4)
Solutions
- Read the inner interpolation error — it names the unresolved variable
- Provide the missing value: packer build -var 'name=myname' ... or a var-file
- Correct the variable/function spelling in the builder name in the template
- Run `packer init` and validate the template (`packer validate`) to catch undefined variables before building
Example fix
// before (shell)
packer build template.pkr.hcl # builder name uses ${local.env_name}, undefined
// after (shell)
packer build -var 'env_name=prod' template.pkr.hcl Defensive patterns
Strategy: validation
Validate before calling
// Validate the template and all variables before building:
// packer validate -var 'name=myname' template.pkr.hcl
// In code, render names with the same context first:
rendered, err := interpolate.Render(builderName, core.Context())
if err != nil {
return fmt.Errorf("builder %q uses an unresolvable variable: %w", builderName, err)
} Try / catch
if err := core.Initialize(); err != nil {
if strings.Contains(err.Error(), "Error interpolating builder") {
return fmt.Errorf("template references undefined variables; check -var/-var-file: %w", err)
}
return err
} Prevention
- Run `packer validate` with your var-files in CI before builds
- Avoid interpolating variables into builder names unless they are guaranteed in scope
- Use `packer inspect` to see which variables a template requires
- Keep variable definitions and defaults in the template to reduce missing-var surprises
When it happens
Trigger: Calling packer's build/init path with a template whose builder name contains variables (e.g. "{{user `name`}}") that are undefined, misspelled, or not provided via -var/-var-file/env, so interpolate.Render(b.Name, core.Context()) errors.
Common situations: Renaming builders to include user variables and forgetting to pass -var; typos in variable names; using functions/variables unavailable at name-interpolation time; legacy JSON templates referencing variables removed in a template refactor.
Related errors
- Error interpolating output value: %s
- Failed to interpolate %s: Please make sure that the variable
- Error parsing target template: %s
- Error parsing target template: %s
- Error interpolating custom data: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/cd6b819f6db97c7a.
Report an issue: GitHub.