hashicorp/packer · error
Error interpolating output value: %s
Error message
Error interpolating output value: %s
What it means
In PostProcess, the compress post-processor renders the validated output_path template with interpolate.Render. Validation in Configure passed, but rendering failed at runtime — usually because a template variable (e.g. build name, generated data) could not be resolved in the current context.
Source
Thrown at post-processor/compress/post-processor.go:136
stateData := artifact.State("generated_data")
if stateData != nil {
// Make sure it's not a nil map so we can assign to it later.
generatedData = stateData.(map[interface{}]interface{})
}
// If stateData has a nil map generatedData will be nil
// and we need to make sure it's not
if generatedData == nil {
generatedData = make(map[interface{}]interface{})
}
// These are extra variables that will be made available for interpolation.
generatedData["BuildName"] = p.config.PackerBuildName
generatedData["BuilderType"] = p.config.PackerBuilderType
p.config.ctx.Data = generatedData
target, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
return nil, false, false, fmt.Errorf("Error interpolating output value: %s", err)
} else {
fmt.Println(target)
}
newArtifact := &Artifact{Path: target}
if err = os.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {
return nil, false, false, fmt.Errorf(
"Unable to create dir for archive %s: %s", target, err)
}
outputFile, err := os.Create(target)
if err != nil {
return nil, false, false, fmt.Errorf(
"Unable to create archive %s: %s", target, err)
}
defer outputFile.Close()
// Setup output interface. If we're using compression, output is aView on GitHub (pinned to eb36e3c3e4)
Solutions
- Replace the failing variable in output_path with one available at post-process time (BuildName/BuilderType/timestamp)
- Run within a standard packer build so generated data (PackerBuildName, PackerBuilderType) is populated
- Simplify output_path to a static path plus timestamp if dynamic variables are not required
- Check the underlying error text to identify the unresolved variable
Example fix
// before
output = "out/{{ .SomeUnknownVar }}.tar.gz"
// after
output = "out/{{ .BuildName }}.tar.gz" Defensive patterns
Strategy: try-catch
Validate before calling
// pre-render with the same context data to surface unknown variables early
if _, err := interpolate.Render(cfg.OutputPath, ctx); err != nil {
return fmt.Errorf("output_path cannot be rendered: %w", err)
} Try / catch
target, err := interpolate.Render(cfg.OutputPath, ctx)
if err != nil {
// fall back to a static, timestamped path
target = fmt.Sprintf("output-%d.bin", time.Now().Unix())
} Prevention
- Use only variables populated in the post-process context (BuildName, BuilderType, timestamp)
- Run inside a standard packer build so generated data is set
- Prefer static paths plus timestamp over exotic template variables
When it happens
Trigger: interpolate.Render(p.config.OutputPath, &p.config.ctx) errors during PostProcess — typically an unknown variable that only appears at runtime, or context data missing when invoked programmatically.
Common situations: Using {{ .BuildName }} or similar when the generated-data key isn't populated by the invoking pipeline; mixing legacy JSON templates with HCL2-only variables; calling the post-processor outside a normal packer build flow.
Related errors
- Error interpolating builder '%s': %s
- Error parsing target template: %s
- Error interpolating custom data: %s
- Error parsing target template: %s
- Error parsing target template: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/20ce1b5f2abefe2d.
Report an issue: GitHub.