{"record":{"id":"cd6b819f6db97c7a","repo":"hashicorp/packer","slug":"error-interpolating-builder-s-s","errorCode":null,"errorMessage":"Error interpolating builder '%s': %s","messagePattern":"Error interpolating builder '(.+?)': (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packer/core.go","lineNumber":187,"sourceCode":"\nfunc (core *Core) initialize() error {\n\tif err := core.validate(); err != nil {\n\t\treturn err\n\t}\n\tif err := core.init(); err != nil {\n\t\treturn err\n\t}\n\tfor _, secret := range core.secrets {\n\t\tRegisterSecret(secret)\n\t}\n\n\t// Go through and interpolate all the build names. We should be able\n\t// to do this at this point with the variables.\n\tcore.builds = make(map[string]*template.Builder)\n\tfor _, b := range core.Template.Builders {\n\t\tv, err := interpolate.Render(b.Name, core.Context())\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error interpolating builder '%s': %s\",\n\t\t\t\tb.Name, err)\n\t\t}\n\n\t\tcore.builds[v] = b\n\t}\n\n\treturn nil\n}\n\nfunc (c *Core) PluginRequirements() (plugingetter.Requirements, hcl.Diagnostics) {\n\treturn nil, hcl.Diagnostics{\n\t\t&hcl.Diagnostic{\n\t\t\tSummary:  \"Packer plugins currently only works with HCL2 configuration templates\",\n\t\t\tDetail:   \"Please manually install plugins with the plugins command or use a HCL2 configuration that will do that for you.\",\n\t\t\tSeverity: hcl.DiagError,\n\t\t},\n\t}","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/packer/core.go#L169-L205","documentation":"During Core initialization (packer/core.go initialize), builder names from the template are rendered through HCL2/interpolation with the core's context. If rendering a builder's Name fails (e.g. an unknown or unresolvable user variable), initialize returns \"Error interpolating builder '%s': %s\" naming the builder and the interpolation error. Core initialization then aborts before any build runs.","triggerScenarios":"Calling packer's build/init path with a template whose builder name contains variables (e.g. \"{{user `name`}}\") that are undefined, misspelled, or not provided via -var/-var-file/env, so interpolate.Render(b.Name, core.Context()) errors.","commonSituations":"Renaming builders to include user variables and forgetting to pass -var; typos in variable names; using functions/variables unavailable at name-interpolation time; legacy JSON templates referencing variables removed in a template refactor.","solutions":["Read the inner interpolation error — it names the unresolved variable","Provide the missing value: packer build -var 'name=myname' ... or a var-file","Correct the variable/function spelling in the builder name in the template","Run `packer init` and validate the template (`packer validate`) to catch undefined variables before building"],"exampleFix":"// before (shell)\npacker build template.pkr.hcl   # builder name uses ${local.env_name}, undefined\n// after (shell)\npacker build -var 'env_name=prod' template.pkr.hcl","handlingStrategy":"validation","validationCode":"// Validate the template and all variables before building:\n//   packer validate -var 'name=myname' template.pkr.hcl\n// In code, render names with the same context first:\nrendered, err := interpolate.Render(builderName, core.Context())\nif err != nil {\n    return fmt.Errorf(\"builder %q uses an unresolvable variable: %w\", builderName, err)\n}","typeGuard":null,"tryCatchPattern":"if err := core.Initialize(); err != nil {\n    if strings.Contains(err.Error(), \"Error interpolating builder\") {\n        return fmt.Errorf(\"template references undefined variables; check -var/-var-file: %w\", err)\n    }\n    return err\n}","preventionTips":["Run `packer validate` with your var-files in CI before builds","Avoid interpolating variables into builder names unless they are guaranteed in scope","Use `packer inspect` to see which variables a template requires","Keep variable definitions and defaults in the template to reduce missing-var surprises"],"tags":["interpolation","hcl2","variables","template"],"backgroundTag":"unresolved-variable-interpolation","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"}