hashicorp/packer · error

Error parsing target template: %s

Error message

Error parsing target template: %s

What it means

During Configure, the compress post-processor validates the output path as an HCL2 template with interpolate.Validate. This error means the output_path string contains template syntax that fails to parse (unbalanced braces, invalid function calls, bad variables), so the path can never be rendered.

Source

Thrown at post-processor/compress/post-processor.go:100

	}

	if p.config.OutputPath == "" {
		p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}"
	}

	if p.config.CompressionLevel > pgzip.BestCompression {
		p.config.CompressionLevel = pgzip.BestCompression
	}
	// Technically 0 means "don't compress" but I don't know how to
	// differentiate between "user entered zero" and "user entered nothing".
	// Also, why bother creating a compressed file with zero compression?
	if p.config.CompressionLevel == -1 || p.config.CompressionLevel == 0 {
		p.config.CompressionLevel = pgzip.DefaultCompression
	}

	if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {
		errs = packersdk.MultiErrorAppend(
			errs, fmt.Errorf("Error parsing target template: %s", err))
	}

	p.config.detectFromFilename()

	if len(errs.Errors) > 0 {
		return errs
	}

	return nil
}

func (p *PostProcessor) PostProcess(
	ctx context.Context,
	ui packersdk.Ui,
	artifact packersdk.Artifact,
) (packersdk.Artifact, bool, bool, error) {
	var generatedData map[interface{}]interface{}
	stateData := artifact.State("generated_data")

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Fix the output_path template syntax (balance all {{ }} pairs)
  2. Run packer validate to confirm the template parses
  3. Only use variables/functions valid in post-processor context (e.g. .BuildName, timestamp)
  4. If you literally need braces in the filename, escape them per HCL2 interpolation rules

Example fix

// before
output = "out/{{timestamp}.tar.gz"
// after
output = "out/{{timestamp}}.tar.gz"
Defensive patterns

Strategy: validation

Validate before calling

if err := interpolate.Validate(cfg.OutputPath, ctx); err != nil {
    return fmt.Errorf("output_path template invalid: %w", err)
}

Try / catch

err := pp.Configure(cfg)
if err != nil {
    var errs *packersdk.MultiError
    if errors.As(err, &errs) {
        for _, e := range errs.Errors {
            // log each config validation error, e.g. template parse failure
        }
    }
}

Prevention

When it happens

Trigger: p.config.OutputPath contains {{ ... }} sequences that interpolate.Validate cannot parse — e.g. '{{user', unmatched '}}', or a call to a nonexistent/invalid function in output_path.

Common situations: Typos in template syntax like '{{timestamp}' (missing braces); using variables unavailable in a post-processor context; shell-style '{...}' patterns misread as template syntax; paths copied from docs with broken markup.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/608cb9a75c24fd34. Report an issue: GitHub.