{"record":{"id":"1f7bce47693cbca3","repo":"hashicorp/terraform","slug":"argument-q-is-required","errorCode":null,"errorMessage":"argument %q is required","messagePattern":"argument %q is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/backendbase/sdklike.go","lineNumber":227,"sourceCode":"\n\t\trawStr := \"\"\n\t\tif !vStr.IsNull() {\n\t\t\trawStr = vStr.AsString()\n\t\t}\n\n\t\tif rawStr == \"\" {\n\t\t\tfor _, envName := range defs.EnvVars {\n\t\t\t\trawStr = os.Getenv(envName)\n\t\t\t\tif rawStr != \"\" {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif rawStr == \"\" {\n\t\t\trawStr = defs.Fallback\n\t\t}\n\t\tif defs.Required && rawStr == \"\" {\n\t\t\treturn cty.NilVal, fmt.Errorf(\"argument %q is required\", attrName)\n\t\t}\n\n\t\t// As a special case, if we still have an empty string and the original\n\t\t// value was null then we'll preserve the null. This is a compromise,\n\t\t// assuming that SDKLikeData knows how to treat a null value as a\n\t\t// zero value anyway and if we preserve the null then the recipient\n\t\t// of this result can still use the cty.Value result directly to\n\t\t// distinguish between the value being set explicitly to empty in\n\t\t// the config vs. being entirely unset.\n\t\tif rawStr == \"\" && givenVal.IsNull() {\n\t\t\tretAttrs[attrName] = givenVal\n\t\t\tcontinue\n\t\t}\n\n\t\t// By the time we get here, rawStr should be empty only if the original\n\t\t// value was unset and all of the fallback environment variables were\n\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","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/backend/backendbase/sdklike.go#L209-L245","documentation":"Thrown by SDKLikeDefaults.ApplyTo when a backend configuration attribute marked Required has no value from any source. The attribute was not set in HCL config, none of its declared environment variables (EnvVars) are set, and no Fallback default exists. This emulates the legacy Terraform SDK 'Required + EnvDefaultFunc' behaviour during backend config preparation.","triggerScenarios":"A backend block (e.g. backend 's3' or 'azurerm') omits a required attribute and the corresponding environment variable is also unset. Triggered during terraform init when PrepareConfig/Configure calls ApplyTo and a Required attribute's rawStr is empty after checking config, EnvVars, and Fallback.","commonSituations":"Missing region/account/credentials in a backend block while assuming an env var like AWS_DEFAULT_REGION or ARM_STORAGE_ACCOUNT_NAME will supply it; switching machines/CI where env vars are not exported; renaming an env var without updating both shell and config.","solutions":["Set the required attribute explicitly in the backend {} block in your Terraform configuration.","Export the environment variable the backend expects for that attribute (check the backend's schema EnvVars list).","If the value should have a default, add a non-empty Fallback in the backend's SDKLikeDefaults registration."],"exampleFix":"// before (missing required attr)\nbackend \"azurerm\" {\n  resource_group_name  = \"rg\"\n  container_name        = \"tfstate\"\n}\n// after\nbackend \"azurerm\" {\n  resource_group_name  = \"rg\"\n  storage_account_name = \"mystorageacct\"\n  container_name        = \"tfstate\"\n  key                   = \"terraform.tfstate\"\n}","handlingStrategy":"validation","validationCode":"// Before calling backend Configure, ensure every required attribute is present.\nfunc requiredAttrsPresent(cfg cty.Value, required []string) error {\n    for _, a := range required {\n        v := cfg.GetAttr(a)\n        if v.IsNull() || (v.Type() == cty.String && v.AsString() == \"\") {\n            return fmt.Errorf(\"argument %q is required\", a)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Go: handle the error returned from ApplyTo / Configure\nval, err := defaults.ApplyTo(config)\nif err != nil {\n    return fmt.Errorf(\"backend config invalid: %w\", err)\n}","preventionTips":["Document and enforce required backend attributes in CI config validation before terraform init.","Use a wrapper script that checks required env vars are exported (and non-empty) before running terraform.","Keep backend schema docs in-repo listing every Required attribute and its env var fallbacks."],"tags":["config","backend","environment-variables","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}