{"record":{"id":"608cb9a75c24fd34","repo":"hashicorp/packer","slug":"error-parsing-target-template-s-608cb9","errorCode":null,"errorMessage":"Error parsing target template: %s","messagePattern":"Error parsing target template: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":100,"sourceCode":"\t}\n\n\tif p.config.OutputPath == \"\" {\n\t\tp.config.OutputPath = \"packer_{{.BuildName}}_{{.BuilderType}}\"\n\t}\n\n\tif p.config.CompressionLevel > pgzip.BestCompression {\n\t\tp.config.CompressionLevel = pgzip.BestCompression\n\t}\n\t// Technically 0 means \"don't compress\" but I don't know how to\n\t// differentiate between \"user entered zero\" and \"user entered nothing\".\n\t// Also, why bother creating a compressed file with zero compression?\n\tif p.config.CompressionLevel == -1 || p.config.CompressionLevel == 0 {\n\t\tp.config.CompressionLevel = pgzip.DefaultCompression\n\t}\n\n\tif err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {\n\t\terrs = packersdk.MultiErrorAppend(\n\t\t\terrs, fmt.Errorf(\"Error parsing target template: %s\", err))\n\t}\n\n\tp.config.detectFromFilename()\n\n\tif len(errs.Errors) > 0 {\n\t\treturn errs\n\t}\n\n\treturn nil\n}\n\nfunc (p *PostProcessor) PostProcess(\n\tctx context.Context,\n\tui packersdk.Ui,\n\tartifact packersdk.Artifact,\n) (packersdk.Artifact, bool, bool, error) {\n\tvar generatedData map[interface{}]interface{}\n\tstateData := artifact.State(\"generated_data\")","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the output_path template syntax (balance all {{ }} pairs)","Run packer validate to confirm the template parses","Only use variables/functions valid in post-processor context (e.g. .BuildName, timestamp)","If you literally need braces in the filename, escape them per HCL2 interpolation rules"],"exampleFix":"// before\noutput = \"out/{{timestamp}.tar.gz\"\n// after\noutput = \"out/{{timestamp}}.tar.gz\"","handlingStrategy":"validation","validationCode":"if err := interpolate.Validate(cfg.OutputPath, ctx); err != nil {\n    return fmt.Errorf(\"output_path template invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"err := pp.Configure(cfg)\nif err != nil {\n    var errs *packersdk.MultiError\n    if errors.As(err, &errs) {\n        for _, e := range errs.Errors {\n            // log each config validation error, e.g. template parse failure\n        }\n    }\n}","preventionTips":["Balance all {{ }} pairs in output_path","Only reference variables valid in post-processor context","Run packer validate before every build","Avoid literal braces in filenames or escape them properly"],"tags":["hcl2","template","configuration","validation"],"backgroundTag":"template-parse-error","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}