hashicorp/packer · error
error parsing output_dir template: %w
Error message
error parsing output_dir template: %w
What it means
During Configure, the provenance post-processor validates the `output_dir` string with `interpolate.Validate` before any build runs. Malformed template syntax (unbalanced braces, unknown functions, invalid variable names) returns `error parsing output_dir template: %w`. Configure fails immediately, so the build never starts.
Source
Thrown at post-processor/provenance/post-processor.go:158
if p.config.SBOMFormat == "" {
p.config.SBOMFormat = string(internalsbom.FormatCycloneDX)
}
if p.config.SBOMScope == "" {
p.config.SBOMScope = internalsbom.ScopeSquashed
}
if p.config.SigningMode == "" {
p.config.SigningMode = internalattestation.SigningModeNone
}
if p.config.FulcioURL == "" {
p.config.FulcioURL = "https://fulcio.sigstore.dev"
}
if p.config.RekorURL == "" {
p.config.RekorURL = "https://rekor.sigstore.dev"
}
if p.config.OutputDir != "" {
if err := interpolate.Validate(p.config.OutputDir, &p.config.ctx); err != nil {
return fmt.Errorf("error parsing output_dir template: %w", err)
}
}
if _, err := p.signingBackendConfig(); err != nil {
return err
}
if p.generateSBOM == nil {
p.generateSBOM = func(ctx context.Context, cfg internalsbom.Config) ([]byte, error) {
return internalsbom.NewGenerator(cfg).Generate(ctx)
}
}
return nil
}
func (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, source packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {
if p.config.Provenance.False() {View on GitHub (pinned to eb36e3c3e4)
Solutions
- Fix the template syntax in `output_dir`; ensure `{{ .Variable }}` style with balanced braces.
- Run `packer validate` to check the template before building.
- Read the wrapped error after the colon for the exact parse offset/function.
- If you don't need templating, use a plain literal path with no `{{ }}` at all.
Example fix
// before
output_dir = "attestations/{{ .BuildName"
// after
output_dir = "attestations/${build.name}" Defensive patterns
Strategy: validation
Validate before calling
// validate output_dir template at config-load time
if err := interpolate.Validate(cfg.OutputDir, &ctx); err != nil {
return fmt.Errorf("bad output_dir: %w", err)
} Try / catch
// Configure already returns the error; just fail fast with context
if err := pp.Configure(raws); err != nil {
return fmt.Errorf("provenance config rejected: %w", err)
} Prevention
- Run `packer validate` before every build.
- Avoid hand-writing `{{ }}` templates; copy known-good examples.
- Use plain literal paths when templating isn't needed.
- Escape braces if you need literal `{{` in output paths.
When it happens
Trigger: Setting `output_dir` in the provenance post-processor to a value like `out/{{ .BuildName` (unclosed `{{`) or using an unknown function `{{ notAFunction "x" }}`. The error surfaces as a Configure failure at the start of `packer build`.
Common situations: Typos in template functions; HCL2 strings where `{{` must be escaped as `{{` inside quotes plus `%{` for directives confusion; porting JSON-templates syntax into HCL2.
Related errors
- ErrInvalidCompressionLevel
- Error parsing target template: %s
- signer and key must match when both are set
- signing_mode %q requires signer or key
- Bad script '%s': %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/55c9a65be411e208.
Report an issue: GitHub.