Skip to main content
In this lesson we cover the terraform validate command — a fast, local validation step that checks your Terraform configuration files for syntax and structural correctness before you run terraform plan or terraform apply.
A purple-themed slide titled "Terraform Validate" with the subtitle "Validate Your Configurations" and explanatory text about the terraform validate command. In the background, a small group of people are gathered around a laptop, appearing to discuss or review something.

What terraform validate checks

  • Verifies HCL syntax and the overall block structure.
  • Validates resource blocks against provider schemas to ensure required attributes and attribute types are present.
  • Detects references to undeclared variables, misspelled resource names, or invalid attribute references.
Example configuration main.tf:
When you run terraform validate, Terraform will parse and analyze the configuration above for syntax errors, missing required attributes, and incorrect references — all without contacting any cloud providers.

Offline validation — what that means

terraform validate runs entirely offline. It uses the provider schemas that were downloaded during terraform init to perform checks, but it does not make API calls to providers. Therefore:
  • It will catch local issues quickly (typos, missing arguments, incorrect HCL).
  • It will not verify provider-level state or external resources (for example, whether an AMI ID exists in AWS).
  • Provider-dependent checks that require network access happen later, during terraform plan or terraform apply.

Quick reference — checks vs. limitations

Workflow and requirement

The validate step depends on provider schemas that Terraform downloads during terraform init. Because of this dependency, always run terraform init before terraform validate. Typical core workflow:
Run terraform init first. If you run terraform validate before initialization, Terraform will fail and prompt you to run terraform init because it needs provider information to validate resource blocks.
Remember: terraform validate is a quick, local sanity check to catch syntax and structural problems early. It complements — but does not replace — terraform plan and terraform apply, which perform provider-level validation and resource changes.

Watch Video