# Error: Reference to undeclared input variable: "var.environment" is not declared in the root module

- **ID:** `terraform/terraform-validate-undeclared-variable`
- **Domain:** terraform
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

A configuration file references a variable (var.*) that has not been declared with a variable block in any of the module's .tf files.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Terraform 1.0.0 | active | — | — |
| Terraform 1.5.0 | active | — | — |
| Terraform 1.6.0 | active | — | — |

## Workarounds

1. **Declare the missing variable in a .tf file (e.g., variables.tf) with an appropriate type and optional default.** (95% success)
   ```
   Declare the missing variable in a .tf file (e.g., variables.tf) with an appropriate type and optional default.
   ```
2. **If the variable is meant to come from a module, ensure the module's outputs are correctly referenced. Use module.<module_name>.<output_name> instead of var.<name>.** (85% success)
   ```
   If the variable is meant to come from a module, ensure the module's outputs are correctly referenced. Use module.<module_name>.<output_name> instead of var.<name>.
   ```
3. **If the variable is not needed, replace the reference with a literal value or a local value.** (80% success)
   ```
   If the variable is not needed, replace the reference with a literal value or a local value.
   ```

## Dead Ends

- **** — The .tfvars file only provides values; the variable must first be declared with a variable block in a .tf file. (95% fail)
- **** — Changing the prefix doesn't create the variable. 'local' requires a locals block, which is a different construct. (80% fail)
- **** — The issue is a missing variable declaration in the root module, not a missing module. Init doesn't add variable declarations. (90% fail)
