hashicorp/terraform · error
attribute %q is required
Error message
attribute %q is required
What it means
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.
Source
Thrown at internal/backend/backendbase/sdklike.go:155
v = os.Getenv(envName)
if v != "" {
return v
}
}
}
return v
}
// SDKLikeRequiredWithEnvDefault is a convenience wrapper around
// [SDKLikeEnvDefault] which returns an error if the result is still the
// empty string even after trying all of the fallback environment variables.
//
// This wrapper requires an additional argument specifying the attribute name
// just because that becomes part of the returned error message.
func SDKLikeRequiredWithEnvDefault(attrPath string, v string, envNames ...string) (string, error) {
ret := SDKLikeEnvDefault(v, envNames...)
if ret == "" {
return "", fmt.Errorf("attribute %q is required", attrPath)
}
return ret, nil
}
// SDKLikeDefaults captures legacy-SDK-like default values to help fill the
// gap in abstraction level between the legacy SDK and Terraform's own
// configuration schema model.
type SDKLikeDefaults map[string]SDKLikeDefault
type SDKLikeDefault struct {
EnvVars []string
Fallback string
// Required is for situations where an argument is optional to set
// in the configuration but _must_ eventually be set through the
// combination of the configuration and the environment variables
// in this object.
//View on GitHub (pinned to c9def3e214)
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.
Example fix
// before
backend "http" {
# address omitted, no TF_HTTP_ADDRESS env -> 'attribute "address" is required'
}
// after (option A: config)
backend "http" {
address = "https://state.example.com"
}
// after (option B: env)
// export TF_HTTP_ADDRESS=https://state.example.com Defensive patterns
Strategy: validation
Validate before calling
val, err := backendbase.SDKLikeRequiredWithEnvDefault("address", cfg.Address, "TF_HTTP_ADDRESS")
if err != nil {
return fmt.Errorf("backend http: %w", err)
} Type guard
func isRequiredAttrError(err error) bool {
return err != nil && strings.Contains(err.Error(), "is required")
} Try / catch
addr, err := backendbase.SDKLikeRequiredWithEnvDefault("address", v, "TF_HTTP_ADDRESS")
if err != nil {
// instruct the user to set config or env var
return fmt.Errorf("set 'address' in the backend block or TF_HTTP_ADDRESS in the environment: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- must not be null
- must not be a whole number
- configuration file did not contain profile: %s
- expected type of %s to be int
- expected %s to be in the range (%d - %d), got %d
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/ad3fa8158aee2817.
Report an issue: GitHub.