{"record":{"id":"055e0ba1b8021dd4","repo":"hashicorp/packer","slug":"error-parsing-target-template-s","errorCode":null,"errorMessage":"Error parsing target template: %s","messagePattern":"Error parsing target template: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/checksum/post-processor.go","lineNumber":91,"sourceCode":"\n\tif p.config.ChecksumTypes == nil {\n\t\tp.config.ChecksumTypes = []string{\"md5\"}\n\t}\n\n\tfor _, k := range p.config.ChecksumTypes {\n\t\tif h := getHash(k); h == nil {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Unrecognized checksum type: %s\", k))\n\t\t}\n\t}\n\n\tif p.config.OutputPath == \"\" {\n\t\tp.config.OutputPath = \"packer_{{.BuildName}}_{{.BuilderType}}_{{.ChecksumType}}.checksum\"\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\tif len(errs.Errors) > 0 {\n\t\treturn errs\n\t}\n\n\treturn nil\n}\n\nfunc (p *PostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, artifact packersdk.Artifact) (packersdk.Artifact, bool, bool, error) {\n\tfiles := artifact.Files()\n\tvar h hash.Hash\n\n\tvar generatedData map[interface{}]interface{}\n\tstateData := artifact.State(\"generated_data\")\n\tif stateData != nil {\n\t\t// Make sure it's not a nil map so we can assign to it later.\n\t\tgeneratedData = stateData.(map[interface{}]interface{})","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/checksum/post-processor.go#L73-L109","documentation":"Configuration-time validation for the checksum post-processor: the `output` path is a template processed by Packer's HCL2-style interpolation engine, and interpolate.Validate rejects it when the template is syntactically invalid (unbalanced braces, unknown/misspelled variables used in ways validation rejects, malformed functions).","triggerScenarios":"Setting an `output` value like \"dir/{{.BuildName\" (unclosed placeholder), \"{{.Foo}}\" (unknown variable), or invoking a nonexistent function — interpolate.Validate against the config context fails and the error is appended to errs.","commonSituations":"Hand-edited output paths with typos; copying shell `${VAR}` syntax instead of Packer's {{.Var}}; using variables not in the checksum context (BuildName, BuilderType, ChecksumType).","solutions":["Fix the template syntax — every placeholder must be {{.Variable}} with balanced braces","Only use the supported variables: .BuildName, .BuilderType, .ChecksumType","Test the path with packer validate before running the build"],"exampleFix":"// before\noutput = \"packer/{{.BuildName}.checksum\"\n// after (closed placeholder / valid vars)\noutput = \"packer/{{.BuildName}}_{{.ChecksumType}}.checksum\"","handlingStrategy":"validation","validationCode":"// Go: pre-validate the output template the same way Packer does\nctx := &interpolate.Context{BuildName: \"b\", BuilderType: \"t\"}\nif err := interpolate.Validate(\"packer_{{.BuildName}}_{{.ChecksumType}}.checksum\", ctx); err != nil {\n    log.Fatalf(\"invalid checksum output template: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := pp.Configure(raws); err != nil {\n    if strings.Contains(err.Error(), \"Error parsing target template\") {\n        // fix output placeholder syntax: {{.Var}} with balanced braces\n    }\n    return err\n}","preventionTips":["Use balanced {{.Variable}} placeholders only","Stick to the supported variables: .BuildName, .BuilderType, .ChecksumType","Don't paste shell ${VAR} syntax into Packer output templates","Run packer validate on every template change"],"tags":["packer","post-processor","checksum","template"],"backgroundTag":"template-syntax-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"}