{"record":{"id":"f8b4dee5b2cd3c7d","repo":"hashicorp/packer","slug":"error-interpolating-source-s","errorCode":null,"errorMessage":"Error interpolating source: %s","messagePattern":"Error interpolating source: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/file/provisioner.go","lineNumber":168,"sourceCode":"\t}\n\n\tif p.config.Direction == \"download\" {\n\t\treturn p.ProvisionDownload(ui, comm)\n\t} else {\n\t\treturn p.ProvisionUpload(ui, comm)\n\t}\n}\n\nfunc (p *Provisioner) ProvisionDownload(ui packersdk.Ui, comm packersdk.Communicator) error {\n\tdst, err := interpolate.Render(p.config.Destination, &p.config.ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error interpolating destination: %s\", err)\n\t}\n\tfor _, src := range p.config.Sources {\n\t\tdst := dst\n\t\tsrc, err := interpolate.Render(src, &p.config.ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error interpolating source: %s\", err)\n\t\t}\n\n\t\t// ensure destination dir exists.  p.config.Destination may either be a file or a dir.\n\t\tdir := dst\n\t\t// if it doesn't end with a /, set dir as the parent dir\n\t\tif !strings.HasSuffix(dst, \"/\") {\n\t\t\tdir = filepath.Dir(dir)\n\t\t} else if !strings.HasSuffix(src, \"/\") && !strings.HasSuffix(src, \"*\") {\n\t\t\tdst = filepath.Join(dst, filepath.Base(src))\n\t\t}\n\t\tui.Say(fmt.Sprintf(\"Downloading %s => %s\", src, dst))\n\n\t\tif dir != \"\" {\n\t\t\terr := os.MkdirAll(dir, os.FileMode(0755))\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/file/provisioner.go#L150-L186","documentation":"In ProvisionDownload, each source path is interpolated with the provisioner's template context. A failure (unknown variable, bad syntax, missing generated data) aborts the whole download loop with this error. The underlying renderer error is embedded after the colon.","triggerScenarios":"direction=download and a source entry contains template placeholders that fail to render, e.g. {{ .HostVars.x }} not exposed by the builder or malformed {{ syntax.","commonSituations":"Download sources using builder-specific generated data not available (e.g. {{ .Flavor }} only on some builders); typos in variable names; using provisioning-state functions not valid in this context.","solutions":["Correct the variable name or syntax in the source path","Use only generated-data keys documented for the builder","Simplify the source path to a literal string if no substitution is needed","Run packer validate / inspect the wrapped error for the exact failing key"],"exampleFix":"// before\nsource = \"{{ .BuildName }}/{{ .Nonexistent }}.log\"\n// after\nsource = \"{{ build_name }}.log\"","handlingStrategy":"try-catch","validationCode":"// Test source templates against the builder's generated data before building:\n// packer validate template.pkr.hcl","typeGuard":null,"tryCatchPattern":"if err := provision(ctx, ui, comm, generated); err != nil {\n    if strings.Contains(err.Error(), \"Error interpolating source\") {\n        // fix the offending source template variable\n    }\n}","preventionTips":["Check builder docs for which {{ . }} fields are available in file sources","Avoid deep variable chains in source globs; keep sources simple","Run packer validate and a smoke build before CI"],"tags":["packer","file-provisioner","interpolation","template"],"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"}