Terraform "No value for required variable" in CI
A variable without a default got no value from a tfvars file, -var flag, or TF_VAR_ env var. In CI, -input=false turns the would-be prompt into a hard error.
What this error means
plan/apply fails with "No value for required variable" naming the variable. It works locally because Terraform prompts interactively, but CI runs non-interactively and fails instead.
terraform
Error: No value for required variable
on variables.tf line 1:
1: variable "environment" {
The root module input variable "environment" is not set, and has no default
value. Use a -var or -var-file command line argument to provide a value for this
variable.Common causes
Variable not supplied in CI
No tfvars file, -var, or TF_VAR_ env var provides the value, and the variable has no default.
Wrong tfvars not auto-loaded
A file not named terraform.tfvars / *.auto.tfvars is not loaded automatically, so its values never apply.
How to fix it
Provide the value non-interactively
Pass a tfvars file or TF_VAR_ env var, and keep -input=false so missing values fail fast.
Terminal
terraform plan -input=false -var-file=env/prod.tfvars
# or via environment:
export TF_VAR_environment=prod
terraform plan -input=falseEnsure tfvars is loaded
- Name auto-loaded files terraform.tfvars or *.auto.tfvars, or pass -var-file explicitly.
- Confirm the file is checked out on the runner.
- Give safe variables sensible defaults to reduce required inputs.
How to prevent it
- Pass -var-file or TF_VAR_ env vars in CI; keep -input=false.
- Default non-secret variables so fewer are required.
- Validate that required tfvars files are present before plan.
Related guides
Terraform "value for undeclared variable" warning/error in CIFix Terraform "value for undeclared variable" in CI - a tfvars file or TF_VAR env var sets a variable the con…
Terraform Variable "validation" Condition Failures in CIFix Terraform variable `validation {}` failures in CI - an input value that violated a custom validation rule…
Terraform "Invalid index" (list/map) in CIFix Terraform "Invalid index" in CI -- indexing a list out of bounds or a map with a missing key, often when…