{"record":{"id":"f02fde27cdfcebd9","repo":"hashicorp/packer","slug":"environment-variable-not-in-format-key-value-s-f02fde","errorCode":null,"errorMessage":"Environment variable not in format 'key=value': %s","messagePattern":"Environment variable not in format 'key=value': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":179,"sourceCode":"\t\t\terrors.New(\"Either a script file or inline script must be specified.\"))\n\t} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only a script file or an inline script can be specified, not both.\"))\n\t}\n\n\tfor _, path := range p.config.Scripts {\n\t\tif _, err := os.Stat(path); err != nil {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Bad script '%s': %s\", path, err))\n\t\t}\n\t}\n\n\t// Do a check for bad environment variables, such as '=foo', 'foobar'\n\tfor _, kv := range p.config.Vars {\n\t\tvs := strings.SplitN(kv, \"=\", 2)\n\t\tif len(vs) != 2 || vs[0] == \"\" {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Environment variable not in format 'key=value': %s\", kv))\n\t\t}\n\t}\n\n\tif errs != nil && len(errs.Errors) > 0 {\n\t\treturn errs\n\t}\n\n\treturn nil\n}\n\nfunc (p *Provisioner) Provision(ctx context.Context, ui packersdk.Ui, comm packersdk.Communicator, generatedData map[string]interface{}) error {\n\tif generatedData == nil {\n\t\tgeneratedData = make(map[string]interface{})\n\t}\n\tp.generatedData = generatedData\n\n\tscripts := make([]string, len(p.config.Scripts))\n\tcopy(scripts, p.config.Scripts)","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L161-L197","documentation":"The shell provisioner validates that every entry in the vars configuration is in 'key=value' form, since each is later exported as an environment variable on the guest. An entry with no '=' or an empty key fails validation and is collected into Prepare's error list.","triggerScenarios":"vars contains entries like 'foo' (no =), '=value' (empty key), or whitespace/empty strings in the Vars list.","commonSituations":"Passing env var names only (assuming Packer reads them from the host); quoting mistakes in JSON/HCL that drop the '='; building vars arrays programmatically and including empty elements; values containing '=' are fine (SplitN with limit 2), but keys with spaces or leading '=' are not.","solutions":["Rewrite each vars entry as KEY=value with a non-empty key.","Values may contain '='; only the first '=' separates key and value — ensure the key part before it is valid.","Remove empty or placeholder strings from the vars array.","If you meant host environment variables, interpolate them in the template (e.g. HCL2 ${env.VAR}) instead of putting bare names in vars."],"exampleFix":"// before\n\"vars\": [\"MY_VAR\", \"=oops\"]\n// after\n\"vars\": [\"MY_VAR=value\"]","handlingStrategy":"validation","validationCode":"# shell: every vars entry must match key=value with a non-empty key\nfor kv in $VARS; do echo \"$kv\" | grep -qE '^[^=]+=.*' || echo \"bad var: $kv\"; done","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write vars entries as KEY=value.","Remove empty strings from programmatic vars arrays.","Interpolate host env vars in the template instead of bare names in vars.","Remember values may contain '='; only the first '=' splits."],"tags":["validation","configuration","shell","environment-variables"],"backgroundTag":"invalid-env-var-format","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"}