{"record":{"id":"2a32ec11fca6897e","repo":"hashicorp/packer","slug":"error-interpolating-custom-data-s","errorCode":null,"errorMessage":"Error interpolating custom data: %s","messagePattern":"Error interpolating custom data: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/manifest/post-processor.go","lineNumber":184,"sourceCode":"\n\t// Write JSON to disk\n\tif out, err := json.MarshalIndent(manifestFile, \"\", \"  \"); err == nil {\n\t\tif err = os.WriteFile(p.config.OutputPath, out, 0664); err != nil {\n\t\t\treturn source, true, true, fmt.Errorf(\"Unable to write %s: %s\", p.config.OutputPath, err)\n\t\t}\n\t} else {\n\t\treturn source, true, true, fmt.Errorf(\"Unable to marshal JSON %s\", err)\n\t}\n\n\t// The manifest should never delete the artifacts it is set to record, so it\n\t// forcibly sets \"keep\" to true.\n\treturn source, true, true, nil\n}\n\nfunc createInterpolatedCustomData(config *Config, customData string) (string, error) {\n\tinterpolatedCmd, err := interpolate.Render(customData, &config.ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Error interpolating custom data: %s\", err)\n\t}\n\treturn interpolatedCmd, nil\n}\n","sourceCodeStart":166,"sourceCodeEnd":188,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/manifest/post-processor.go#L166-L188","documentation":"Packer's manifest post-processor renders the `custom_data` field through the HCL2/template interpolation engine before writing the manifest. If the template engine cannot evaluate the string (unknown function, bad placeholder syntax, invalid variables), createInterpolatedCustomData wraps the engine error in `Error interpolating custom data: %s` and PostProcess aborts. The manifest file is not written or is written without the custom_data entry.","triggerScenarios":"Running `packer build` with a manifest post-processor whose `custom_data` contains invalid interpolation syntax (e.g. `{{build_ID}}` instead of `{{ .BuildName }}`), a call to a nonexistent template function, or context variables not available in the post-processor phase (e.g. some `{{ .HCLConfig... }}` values).","commonSituations":"Copy-pasted templates from docs with the wrong placeholder spacing (`{{build_name}}` vs `{{ .BuildName }}`); using builder-only variables in a post-processor; typos in function names like `timestampa`.","solutions":["Fix the interpolation syntax in `custom_data` (variables need leading dot and spaces: `{{ .BuildName }}`).","Run `packer validate` on the template to catch bad placeholders before building.","Check the wrapped error text after the colon; it names the exact function or variable that failed.","If a variable is genuinely unavailable at post-process time, remove it or move the data into the builder."],"exampleFix":"// before\ncustom_data = { id = \"{{build_ID}}\" }\n// after\ncustom_data = { id = \"{{ uuidv4 }}\" }","handlingStrategy":"validation","validationCode":"// pre-validate custom_data template before the build\nerr := interpolate.Validate(cfg.CustomData, &ctx)\nif err != nil { return fmt.Errorf(\"invalid custom_data: %w\", err) }","typeGuard":null,"tryCatchPattern":"// Go: check error from PostProcess and inspect the wrapped interpolation error\nif err := pp.PostProcess(ctx, ui, artifact); err != nil {\n    if strings.Contains(err.Error(), \"Error interpolating custom data\") {\n        // fall back to plain custom_data or abort with a clear message\n    }\n}","preventionTips":["Run `packer validate` on templates before building.","Use correct `{{ .Variable }}` syntax with dot and spaces.","Only reference variables available in the post-processor context.","Keep custom_data templates simple; build complex values in the builder."],"tags":["interpolation","template","post-processor","manifest"],"backgroundTag":"template-interpolation-failed","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"}