{"record":{"id":"20ce1b5f2abefe2d","repo":"hashicorp/packer","slug":"error-interpolating-output-value-s","errorCode":null,"errorMessage":"Error interpolating output value: %s","messagePattern":"Error interpolating output value: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"post-processor/compress/post-processor.go","lineNumber":136,"sourceCode":"\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{})\n\t}\n\t// If stateData has a nil map generatedData will be nil\n\t// and we need to make sure it's not\n\tif generatedData == nil {\n\t\tgeneratedData = make(map[interface{}]interface{})\n\t}\n\n\t// These are extra variables that will be made available for interpolation.\n\tgeneratedData[\"BuildName\"] = p.config.PackerBuildName\n\tgeneratedData[\"BuilderType\"] = p.config.PackerBuilderType\n\tp.config.ctx.Data = generatedData\n\n\ttarget, err := interpolate.Render(p.config.OutputPath, &p.config.ctx)\n\tif err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\"Error interpolating output value: %s\", err)\n\t} else {\n\t\tfmt.Println(target)\n\t}\n\n\tnewArtifact := &Artifact{Path: target}\n\n\tif err = os.MkdirAll(filepath.Dir(target), os.FileMode(0755)); err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\"Unable to create dir for archive %s: %s\", target, err)\n\t}\n\toutputFile, err := os.Create(target)\n\tif err != nil {\n\t\treturn nil, false, false, fmt.Errorf(\n\t\t\t\"Unable to create archive %s: %s\", target, err)\n\t}\n\tdefer outputFile.Close()\n\n\t// Setup output interface. If we're using compression, output is a","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/post-processor/compress/post-processor.go#L118-L154","documentation":"In PostProcess, the compress post-processor renders the validated output_path template with interpolate.Render. Validation in Configure passed, but rendering failed at runtime — usually because a template variable (e.g. build name, generated data) could not be resolved in the current context.","triggerScenarios":"interpolate.Render(p.config.OutputPath, &p.config.ctx) errors during PostProcess — typically an unknown variable that only appears at runtime, or context data missing when invoked programmatically.","commonSituations":"Using {{ .BuildName }} or similar when the generated-data key isn't populated by the invoking pipeline; mixing legacy JSON templates with HCL2-only variables; calling the post-processor outside a normal packer build flow.","solutions":["Replace the failing variable in output_path with one available at post-process time (BuildName/BuilderType/timestamp)","Run within a standard packer build so generated data (PackerBuildName, PackerBuilderType) is populated","Simplify output_path to a static path plus timestamp if dynamic variables are not required","Check the underlying error text to identify the unresolved variable"],"exampleFix":"// before\noutput = \"out/{{ .SomeUnknownVar }}.tar.gz\"\n// after\noutput = \"out/{{ .BuildName }}.tar.gz\"","handlingStrategy":"try-catch","validationCode":"// pre-render with the same context data to surface unknown variables early\nif _, err := interpolate.Render(cfg.OutputPath, ctx); err != nil {\n    return fmt.Errorf(\"output_path cannot be rendered: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"target, err := interpolate.Render(cfg.OutputPath, ctx)\nif err != nil {\n    // fall back to a static, timestamped path\n    target = fmt.Sprintf(\"output-%d.bin\", time.Now().Unix())\n}","preventionTips":["Use only variables populated in the post-process context (BuildName, BuilderType, timestamp)","Run inside a standard packer build so generated data is set","Prefer static paths plus timestamp over exotic template variables"],"tags":["hcl2","template","interpolation","post-processor"],"backgroundTag":"unresolved-template-variable","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"}