How to fix Error: Failed to read variables from terraform.tfvars in Terraform

TerraformBEGINNERMEDIUMUpdated Dec 30, 2025· 100 views

Terraform cannot read your terraform.tfvars file due to syntax errors, missing variable declarations, file naming issues, or incorrect file paths. Fix the tfvars file syntax and ensure variables are declared in your .tf files.

Quick fix

Fixes Error: Failed to read variables from terraform.tfvars

# List files in current directory
ls -la terraform.tfvars

# Or from parent directory
ls -la your-project/terraform.tfvars
  1. Verify the file exists and is correctly named
  2. Validate the .tfvars file syntax
  3. Declare variables in your .tf files
  4. Check your working directory
terraform — error
# List files in current directory
ls -la terraform.tfvars
# Or from parent directory
ls -la your-project/terraform.tfvars
Error: Failed to read variables from terraform.tfvars

What this error means

Terraform loads variables from terraform.tfvars files, but this error occurs when the file cannot be parsed or accessed. This typically happens when: 1. The .tfvars file has syntax errors (invalid HCL) 2. Variables are defined in terraform.tfvars but not declared in .tf files 3. The file is named incorrectly (e.g., terraform.tfvar instead of terraform.tfvars) 4. The file path is wrong or the file doesn't exist 5. Terraform is being run from the wrong working directory Unlike other tools, Terraform requires that every variable used in .tfvars must be explicitly declared in a .tf file first before you can assign values to it.

Typical symptoms

  • terraform plan or terraform apply fails immediately after displaying the error
  • Variables defined in terraform.tfvars are not loaded by Terraform
  • Terraform prompts for variable values even though terraform.tfvars exists
  • Running terraform validate shows the same error

Common causes

  1. HCL syntax errors in terraform.tfvars (missing quotes, incorrect types, malformed objects)
  2. Variables referenced in terraform.tfvars that are not declared with variable blocks in .tf files
  3. Incorrect file naming (terraform.tfvar, terraform.tfars, or other variations instead of terraform.tfvars)
  4. File path is incorrect or terraform.tfvars is not in the root module directory
  5. Terraform is running from a different directory than where terraform.tfvars is located
  6. File encoding issues or special characters in the .tfvars file
  7. Permission issues preventing Terraform from reading the file

How to fix "Error: Failed to read variables from terraform.tfvars"

1Verify the file exists and is correctly named

Ensure the file is named exactly terraform.tfvars (not terraform.tfvar or terraform.tfvars.json unless you're specifically using JSON format).

bash
# List files in current directory
ls -la terraform.tfvars

# Or from parent directory
ls -la your-project/terraform.tfvars

The file must be in the root module directory where you run terraform commands. If it's in a subdirectory, you'll need to use the -var-file flag.

2Validate the .tfvars file syntax

Check for HCL syntax errors in terraform.tfvars. Common mistakes include:
- Missing quotes around string values: instance_type = t2.micro should be instance_type = "t2.micro"
- Incorrect object/map syntax: tags = { Name = "test" } (must use =)
- Missing commas between properties (not required in HCL but object syntax must be correct)

hcl
# Correct syntax examples
region           = "us-east-1"
instance_count   = 3
enable_feature   = true
tags             = { Name = "web-server", Env = "prod" }
availability_zones = ["us-east-1a", "us-east-1b"]

Review your file character by character for these issues.

3Declare variables in your .tf files

Every variable used in terraform.tfvars must be declared in a .tf file (typically variables.tf). Variable declarations define what variables Terraform expects.

hcl
# variables.tf
variable "region" {
  type        = string
  description = "AWS region"
  default     = "us-east-1"
}

variable "instance_count" {
  type    = number
  default = 1
}

variable "tags" {
  type = map(string)
}

If terraform.tfvars contains a variable that doesn't have a corresponding declaration, Terraform will fail. Add the missing declarations.

4Check your working directory

Terraform must be run from the directory containing your root module .tf files. If terraform.tfvars is in a different location, use the -var-file flag.

bash
# If terraform.tfvars is in current directory (default behavior)
terraform plan

# If terraform.tfvars is elsewhere
terraform plan -var-file="./environments/prod.tfvars"

# Multiple .tfvars files
terraform plan -var-file="./common.tfvars" -var-file="./prod.tfvars"

The auto-loading of terraform.tfvars only works when the file is in the same directory as your .tf files.

5Run terraform validate to get detailed error messages

terraform validate will often provide more specific error details about what's wrong with your configuration and .tfvars files.

bash
terraform validate

This command checks syntax without making any cloud API calls, so it's safe to run repeatedly. It will tell you exactly which line or variable is causing the problem.

Advanced notes

Auto-loading behavior: Terraform automatically loads files named terraform.tfvars or matching the pattern *.auto.tfvars. Files matching *.auto.tfvars are loaded in lexical order. Any other filename requires the -var-file flag.

Variable precedence: If the same variable is set in multiple .tfvars files, the last one loaded wins. The precedence order is: environment variables (TF_VAR_*) → terraform.tfvars → *.auto.tfvars → command-line (-var) → variable defaults.

Terraform Cloud/Enterprise: If using TFE/Cloud with a configured working directory, ensure that working directory setting in the project settings matches where your .tf and .tfvars files are located.

Environment variables: You can also set variables using TF_VAR_variablename environment variables as an alternative to .tfvars files.

Frequently asked questions

What does "Error: Failed to read variables from terraform.tfvars" mean?
tfvars files, but this error occurs when the file cannot be parsed or accessed. This typically happens when: 1. tfvars file has syntax errors (invalid HCL) 2.
How do I fix "Error: Failed to read variables from terraform.tfvars"?
Terraform cannot read your terraform.tfvars file due to syntax errors, missing variable declarations, file naming issues, or incorrect file paths. Fix the tfvars file syntax and ensure variables are declared in your .tf files.
What causes "Error: Failed to read variables from terraform.tfvars"?
HCL syntax errors in terraform.tfvars (missing quotes, incorrect types, malformed objects) Variables referenced in terraform.tfvars that are not declared with variable blocks in .tf files Incorrect file naming (terraform.tfvar, terraform.tfars, or other variations instead of terraform.tfvars)
Is the "Error: Failed to read variables from terraform.tfvars" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading