{"record":{"id":"142de110d04a0869","repo":"hashicorp/terraform","slug":"invalid-value-for-q-s","errorCode":null,"errorMessage":"invalid value for %q: %s","messagePattern":"invalid value for %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/backendbase/sdklike.go","lineNumber":262,"sourceCode":"\t\t// also unset. Otherwise, rawStr contains a string representation of\n\t\t// a value that we now need to convert back to the type that was\n\t\t// originally wanted.\n\t\tswitch ty {\n\t\tcase cty.String:\n\t\t\tretAttrs[attrName] = cty.StringVal(rawStr)\n\t\tcase cty.Bool:\n\t\t\tif rawStr == \"\" {\n\t\t\t\trawStr = \"false\"\n\t\t\t}\n\n\t\t\t// Legacy SDK uses strconv.ParseBool and therefore tolerates a\n\t\t\t// variety of different string representations of true and false,\n\t\t\t// so we'll do the same here. The config itself can't use those\n\t\t\t// alternate forms because HCL's definition of bool prevails there,\n\t\t\t// but the environment variables can use any of these forms.\n\t\t\tbv, err := strconv.ParseBool(rawStr)\n\t\t\tif err != nil {\n\t\t\t\treturn cty.NilVal, fmt.Errorf(\"invalid value for %q: %s\", attrName, err)\n\t\t\t}\n\t\t\tretAttrs[attrName] = cty.BoolVal(bv)\n\t\tcase cty.Number:\n\t\t\tif rawStr == \"\" {\n\t\t\t\trawStr = \"0\"\n\t\t\t}\n\n\t\t\t// This case is a little trickier because cty.Number could be\n\t\t\t// representing either an integer or a float, which each have\n\t\t\t// different interpretations in the legacy SDK. Therefore we'll\n\t\t\t// try integer first and use its result if successful, but then\n\t\t\t// try float as a fallback if not.\n\t\t\tif iv, err := strconv.ParseInt(rawStr, 0, 0); err == nil {\n\t\t\t\tretAttrs[attrName] = cty.NumberIntVal(iv)\n\t\t\t} else if fv, err := strconv.ParseFloat(rawStr, 64); err == nil {\n\t\t\t\tretAttrs[attrName] = cty.NumberFloatVal(fv)\n\t\t\t} else {\n\t\t\t\treturn cty.NilVal, fmt.Errorf(\"invalid value for %q: must be a number\", attrName)","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/backendbase/sdklike.go#L244-L280","documentation":"Thrown by SDKLikeDefaults.ApplyTo when an attribute typed cty.Bool receives a string (typically from an environment variable) that strconv.ParseBool cannot interpret. The legacy SDK allowed environment variables to use alternate boolean spellings (1, t, TRUE, etc.) and this mirrors that, but anything outside ParseBool's accepted set fails.","triggerScenarios":"A boolean backend attribute is populated from an environment variable whose value is not parseable as a bool (e.g. 'yes', 'on', '\"true\"', or an arbitrary string). ParseBool accepts: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.","commonSituations":"Setting an env var like TF_VAR_... or a backend bool env var to 'yes'/'on' (common in shell scripts) instead of 'true'; quoting the value; copy-paste typos.","solutions":["Set the boolean environment variable to one of: true, false, 1, 0, or any strconv.ParseBool-accepted form.","Define the value directly in the backend block as a native HCL bool (true/false) instead of relying on the env var.","Remove stray quotes or whitespace from the environment variable value."],"exampleFix":"# before\nexport SOME_BACKEND_BOOL=yes\n# after\nexport SOME_BACKEND_BOOL=true","handlingStrategy":"validation","validationCode":"// Validate a bool-providing env var against strconv.ParseBool's accepted set before init.\nfunc validBoolEnv(name string) bool {\n    v := os.Getenv(name)\n    if v == \"\" {\n        return true // unset is fine if there's a config/fallback\n    }\n    _, err := strconv.ParseBool(v)\n    return err == nil\n}","typeGuard":null,"tryCatchPattern":"val, err := defaults.ApplyTo(config)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid value for\") {\n        // surface a hint about the expected bool/number format\n    }\n    return err\n}","preventionTips":["Standardize all boolean env vars to lowercase 'true'/'false' across your tooling.","Add a pre-flight env-var lint step in CI that validates types against the backend schema.","Avoid 'yes'/'on'/'1'-style booleans in shared scripts to match ParseBool's accepted set."],"tags":["config","backend","environment-variables","type-conversion","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}