{"record":{"id":"c2076fe8693038ce","repo":"hashicorp/packer","slug":"error-interpolating-destination-s","errorCode":null,"errorMessage":"Error interpolating destination: %s","messagePattern":"Error interpolating destination: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/file/provisioner.go","lineNumber":162,"sourceCode":"\t\tdefer file.Close()\n\t\tif _, err := file.WriteString(p.config.Content); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tp.config.Content = \"\"\n\t\tp.config.Sources = append(p.config.Sources, file.Name())\n\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","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/file/provisioner.go#L144-L180","documentation":"In ProvisionDownload, the destination path is run through Packer's interpolate renderer (to substitute build-generated data like {{ .WinRMUser }} etc.). If the template contains an unknown key, bad syntax, or references data not available, rendering fails and this error aborts the download before any file transfer.","triggerScenarios":"direction=download and config.Destination contains template syntax ({{ }}) that fails to render — unknown variables, malformed placeholders, or generated data keys not exposed by the builder.","commonSituations":"Using {{ .WinRMUser }} on an SSH builder; typos like {{ build_name }} without the right function; escaped braces from shell copying; copy-pasting a destination from another builder type.","solutions":["Fix the template syntax in destination (valid HCL2/Packer template functions or generated data keys)","Only use generated-data variables supported by the builder in use","Remove interpolation braces if a literal path with '{{' was intended","Check packer validate output for the specific interpolation error"],"exampleFix":"// before\ndestination = \"/tmp/{{ .UnsupportedVar }}/out.txt\"\n// after\ndestination = \"/tmp/{{ build_name }}-out.txt\"","handlingStrategy":"try-catch","validationCode":"// Verify the destination template renders with expected generated data before build:\n// packer validate template.pkr.hcl  (interpolation errors surface at validate)\n// and confirm the builder exposes the generated-data keys you use.","typeGuard":null,"tryCatchPattern":"if err := provision(ctx, ui, comm, generated); err != nil {\n    if strings.Contains(err.Error(), \"Error interpolating destination\") {\n        // fix the destination template / generated-data key\n    }\n}","preventionTips":["Only use generated-data keys documented for the specific builder","Prefer literal destination paths unless substitution is required","Run packer validate to catch interpolation problems early"],"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"}