hashicorp/packer · error
error interpolating default value for '%s': %s
Error message
error interpolating default value for '%s': %s
What it means
`renderVarsRecursively` interpolates each variable's default with `interpolate.RenderRegex` and switches on the error type. `nil` means success, `ttmp.ExecError` containing 'variable not set' triggers a retry loop, but any other error type is unexpected and aborts immediately with `error interpolating default value for '%s': %s`, naming the variable key and the underlying interpolation error. This indicates malformed template-engine syntax or a render failure that is not simply an unset user variable.
Source
Thrown at packer/core.go:1016
// variables that still need interpolating for a repeat.
done, err := isDoneInterpolating(kv.Value)
if err != nil {
return ctx, err
}
if done {
deleteKeys = append(deleteKeys, kv.Key)
} else {
shouldRetry = true
}
case ttmp.ExecError:
if strings.Contains(err.Error(), interpolate.ErrVariableNotSetString) {
shouldRetry = true
failedInterpolation = fmt.Sprintf(`"%s": "%s"; error: %s`, kv.Key, kv.Value, err)
} else {
return ctx, err
}
default:
return ctx, fmt.Errorf(
// unexpected interpolation error: abort the run
"error interpolating default value for '%s': %s",
kv.Key, err)
}
}
if !shouldRetry {
break
}
// Clear completed vars from sortedMap before next loop. Do this one
// key at a time because the indices are gonna change ever time you
// delete from the map.
for _, k := range deleteKeys {
for ind, kv := range sortedMap {
if kv.Key == k {
sortedMap = append(sortedMap[:ind], sortedMap[ind+1:]...)
break
}View on GitHub (pinned to eb36e3c3e4)
Solutions
- Look at the variable key named in the error and inspect its default value's `{{ }}` syntax for typos or unclosed braces/backticks.
- Fix or remove the invalid template expression in the variable definition.
- Confirm the function used exists in Packer's interpolation function list (e.g. `timestamp`, `env`, `user`) and is spelled correctly.
- If the variable genuinely references an unset user variable, that case is handled separately — supply the value with `-var` so it resolves instead of erroring.
Example fix
// before
"variables": {
"name": "{{user `base`}}-{{timestampa}}"
}
// after
"variables": {
"name": "{{user `base`}}-{{timestamp}}"
} Defensive patterns
Strategy: try-catch
Validate before calling
// sanity-check a variable default's template syntax before building
for name, val := range variables {
if strings.Count(val, "{{") != strings.Count(val, "}}") ||
strings.Count(val, "`")%2 != 0 {
return fmt.Errorf("variable %s has unbalanced template syntax", name)
}
} Try / catch
// Go: distinguish unexpected interpolation failures
if err := core.Initialize(); err != nil {
if strings.Contains(err.Error(), "error interpolating default value for") {
// extract the key between quotes and surface a config-fix message
return fmt.Errorf("fix variable template syntax: %w", err)
}
return err
} Prevention
- Lint templates (`packer validate`) before every build to catch bad `{{ }}` syntax early.
- Verify template function names against Packer's interpolation function docs.
- Balance backticks and braces when editing variable defaults, especially in JSON templates.
- Prefer HCL2 templates where editors provide syntax highlighting for interpolation blocks.
When it happens
Trigger: Called during `Core.init()`; `interpolate.RenderRegex(kv.Value, ctx, renderFilter)` returns an error that is neither nil nor a `ttmp.ExecError` with the variable-not-set string — e.g. badly nested/unclosed `{{ }}` template blocks, unknown template functions, or other text-template parse/exec failures in a variable default.
Common situations: Typo in a template function inside a variable default (e.g. `{{timestampa}}`); unbalanced backticks or braces in `{{user `foo`}}`; copying shell-style `${}` syntax into a JSON template variable; escaping problems after migrating a template between JSON and HCL2.
Related errors
- Can't tell if interpolation is done: %s
- Failed to interpolate %s: Please make sure that the variable
- Error interpolating destination: %s
- Error interpolating source: %s
- failed to render execute_command: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/71e0bd486ab5964c.
Report an issue: GitHub.