What is the purpose of terraform.tfvars files?

Easy Topic: Terraform May 24, 2026

terraform.tfvars files provide values for your declared variables, keeping configuration separate from the variable definitions. This allows you to have different values per environment without modifying the core modules.

# variables.tf — defines the variable
variable "instance_type" {
  description = "EC2 instance type"
  type        = string
}

# production.tfvars — provides the value
instance_type = "c5.2xlarge"

# development.tfvars
instance_type = "t3.micro"

Never commit .tfvars files containing sensitive values to Git. Use .gitignore and pass sensitive values via environment variables (TF_VAR_*) in CI/CD.

← Previous How do you implement Terraform in a CI/CD... Next → Explain the Terraform resource lifecycle and meta-arguments like...

Practice Similar Questions

Back to Terraform Topics