terraform validate — the Terraform CLI command that performs a local, offline check of your configuration files to catch syntax and structural errors before you run slower, provider-interacting commands.
What terraform validate does
- Checks HCL syntax across your configuration files.
- Validates structural correctness of blocks (resources, modules, providers).
- Verifies required arguments and attribute types against provider schemas (when initialized).
- Confirms referenced variables and outputs are declared.
terraform validate does NOT do
- Make API calls to cloud providers or external services.
- Confirm provider-side resources exist (for example, whether an AMI ID is valid).
- Check cloud permissions or runtime environment constraints.
- Guarantee an apply will succeed.
terraform validate performs an offline schema-aware validation of your configs. It relies on provider schemas downloaded during terraform init, but it does not make any provider API calls, so provider-side problems (missing AMIs, permissions, quotas) will not be detected here.terraform validate inspects for syntax and attribute correctness):
- Whether the referenced AMI actually exists.
- Whether you have permissions to create the resource.
- Whether the resource already exists in the provider.
terraform plan and terraform apply, which interact with provider APIs.
You must run
terraform init before terraform validate. Initialization downloads provider plugins and schemas that validate uses. Running validate without first initializing the working directory will fail and prompt you to run terraform init.terraform validate fits in a typical Terraform workflow
| Step | Command | Purpose |
|---|---|---|
| Initialize | terraform init | Download providers, modules, and schema required for validation and planning. |
| Validate | terraform validate | Fast, local syntax and schema check. |
| Plan | terraform plan | Evaluate changes against provider state; makes API calls. |
| Apply | terraform apply | Apply changes to your infrastructure. |
| Destroy | terraform destroy | Remove infrastructure created by Terraform. |
- Use
terraform validateas a quick pre-commit or CI check to catch syntax/regression issues before running expensive plans. - Combine
terraform validatewithterraform fmt -checkin CI to ensure consistent formatting and valid syntax. - Remember that
validateis not a substitute forterraform plan— always review the plan before applying.
- For the Terraform Associate exam and practical use, remember:
terraform validateis an offline syntax/structure check and requiresterraform initto have been run in the working directory.
- Terraform CLI Docs — validate
- Terraform Init
- Terraform Plan
- HashiCorp Certified: Terraform Associate