Skip to content
Latchkey

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=false

Ensure tfvars is loaded

  1. Name auto-loaded files terraform.tfvars or *.auto.tfvars, or pass -var-file explicitly.
  2. Confirm the file is checked out on the runner.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →