Skip to content

/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

bash
cat > main.tf <<'EOF'
resource "terraform_data" "app" {
  input = var.region
}
EOF
terraform init -input=false -no-color >/dev/null
terraform validate -no-color

Output · 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

variables.tf
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:

modules/network/variables.tf
variable "region" {
  type = string
}
main.tf
module "network" {
  source = "./modules/network"
  region = var.region
}

Sources