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.

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.
main.tf:
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 planorterraform apply.
Quick reference — checks vs. limitations
Workflow and requirement
Thevalidate 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.Links and references
- Terraform CLI documentation: https://developer.hashicorp.com/terraform/cli
terraform initdocs: https://developer.hashicorp.com/terraform/cli/commands/initterraform plandocs: https://developer.hashicorp.com/terraform/cli/commands/plan