/errors/terraform/reference-to-undeclared-input-variable
Terraform: Reference to undeclared input variable
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Terraform v1.16.6updated 2026-10-20
- tool
- Terraform
- exit code
- 1
- versions
- Terraform 1.x, OpenTofu 1.x
- os
- any
Terraform reports Reference to undeclared input variable when an expression uses var.NAME and the current module has no variable "NAME" block. Every module, including each child module, only sees the variables it declares itself; values in terraform.tfvars do not declare anything.
Reproduce it
cat > main.tf <<'EOF'
resource "terraform_data" "app" {
input = var.region
}
EOF
terraform init -input=false -no-color >/dev/null
terraform validate -no-colorOutput · exit 1
Error: Reference to undeclared input variable
on main.tf line 2, in resource "terraform_data" "app":
2: input = var.region
An input variable with the name "region" has not been declared. This variable
can be declared with a variable "region" {} block.Fix: declare the variable
variable "region" {
type = string
description = "Region to deploy into"
default = "eu-west-1"
}Fix: pass it to a child module
A variable from the root module is not visible inside ./modules/network. Declare it there and pass it explicitly:
variable "region" {
type = string
}module "network" {
source = "./modules/network"
region = var.region
}Sources
Related pages
config · terraformTerraform variable precedence: tfvars, auto.tfvars, -var and TF_VAR_Terraform reads variables from TF_VAR_ environment variables, terraform.tfvars, *.auto.tfvars, then -var-file and -var. Later sources win, shown with plans.errors · terraformTerraform: Error: Unsupported argument. An argument named "x" is not expected hereTerraform fails with Unsupported argument, An argument named "name" is not expected here, when a block sets an attribute its resource or module lacks.cheat sheets · terraformTerraform cheat sheet: init, plan, apply, state and workspacesTerraform cheat sheet: init and upgrade, fmt and validate, plan and apply, outputs, state list, mv and rm, import, workspaces, and common language syntax.