{"record":{"id":"ad3fa8158aee2817","repo":"hashicorp/terraform","slug":"attribute-q-is-required","errorCode":null,"errorMessage":"attribute %q is required","messagePattern":"attribute %q is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/backendbase/sdklike.go","lineNumber":155,"sourceCode":"\t\t\tv = os.Getenv(envName)\n\t\t\tif v != \"\" {\n\t\t\t\treturn v\n\t\t\t}\n\t\t}\n\t}\n\treturn v\n}\n\n// SDKLikeRequiredWithEnvDefault is a convenience wrapper around\n// [SDKLikeEnvDefault] which returns an error if the result is still the\n// empty string even after trying all of the fallback environment variables.\n//\n// This wrapper requires an additional argument specifying the attribute name\n// just because that becomes part of the returned error message.\nfunc SDKLikeRequiredWithEnvDefault(attrPath string, v string, envNames ...string) (string, error) {\n\tret := SDKLikeEnvDefault(v, envNames...)\n\tif ret == \"\" {\n\t\treturn \"\", fmt.Errorf(\"attribute %q is required\", attrPath)\n\t}\n\treturn ret, nil\n}\n\n// SDKLikeDefaults captures legacy-SDK-like default values to help fill the\n// gap in abstraction level between the legacy SDK and Terraform's own\n// configuration schema model.\ntype SDKLikeDefaults map[string]SDKLikeDefault\n\ntype SDKLikeDefault struct {\n\tEnvVars  []string\n\tFallback string\n\n\t// Required is for situations where an argument is optional to set\n\t// in the configuration but _must_ eventually be set through the\n\t// combination of the configuration and the environment variables\n\t// in this object.\n\t//","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/backendbase/sdklike.go#L137-L173","documentation":"Returned by SDKLikeRequiredWithEnvDefault when, after checking the provided value and every fallback environment variable, the result is still empty. It is the SDK-style 'required attribute, possibly via env var' helper used by backends to enforce that a mandatory string attribute is supplied through config or environment — the attrPath is interpolated into the message to name the offending field.","triggerScenarios":"Returned at internal/backend/backendbase/sdklike.go:155 when SDKLikeEnvDefault returns \"\". SDKLikeEnvDefault returns the value if non-empty, else the first non-empty env var among envNames, else \"\". So the error means: attribute unset in config AND none of the listed env vars are set.","commonSituations":"A required backend attribute is omitted from the backend block and no environment fallback is exported. e.g. an http backend missing `address` with no matching env var. Migrating a backend where the attribute used to be defaulted but is now required. CI that set TF_CLI_args but not the backend-specific env vars.","solutions":["Add the required attribute to the backend block, e.g. `address = \"https://state.example.com\"`.","Export the documented fallback environment variable(s) for that attribute in your shell/CI.","Check the backend's docs for the exact env var names and set the appropriate one.","If the attribute should be optional, change the backend to call SDKLikeEnvDefault (non-required) or supply a fallback."],"exampleFix":"// before\nbackend \"http\" {\n  # address omitted, no TF_HTTP_ADDRESS env -> 'attribute \"address\" is required'\n}\n// after (option A: config)\nbackend \"http\" {\n  address = \"https://state.example.com\"\n}\n// after (option B: env)\n// export TF_HTTP_ADDRESS=https://state.example.com","handlingStrategy":"validation","validationCode":"val, err := backendbase.SDKLikeRequiredWithEnvDefault(\"address\", cfg.Address, \"TF_HTTP_ADDRESS\")\nif err != nil {\n    return fmt.Errorf(\"backend http: %w\", err)\n}","typeGuard":"func isRequiredAttrError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"is required\")\n}","tryCatchPattern":"addr, err := backendbase.SDKLikeRequiredWithEnvDefault(\"address\", v, \"TF_HTTP_ADDRESS\")\nif err != nil {\n    // instruct the user to set config or env var\n    return fmt.Errorf(\"set 'address' in the backend block or TF_HTTP_ADDRESS in the environment: %w\", err)\n}","preventionTips":["Always set required backend string attributes in config or export the documented env vars.","Document which env vars each backend honors.","Validate required attributes at config-load time with a clear message."],"tags":["backend","config","validation","required-attribute","env"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}