Skip to main content
In this lesson we cover 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.
What 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.
Example resource snippet (what terraform validate inspects for syntax and attribute correctness):
resource "aws_instance" "example" {
  ami           = "ami-12345678"
  instance_type = "t2.micro"

  tags = {
    Name = "example"
  }
}
Because validation is offline, it will not detect provider-level issues such as:
  • Whether the referenced AMI actually exists.
  • Whether you have permissions to create the resource.
  • Whether the resource already exists in the provider.
Those problems are detected later by 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.
Where terraform validate fits in a typical Terraform workflow
StepCommandPurpose
Initializeterraform initDownload providers, modules, and schema required for validation and planning.
Validateterraform validateFast, local syntax and schema check.
Planterraform planEvaluate changes against provider state; makes API calls.
Applyterraform applyApply changes to your infrastructure.
Destroyterraform destroyRemove infrastructure created by Terraform.
Example command sequence
terraform init
terraform validate
terraform plan
terraform apply
terraform destroy
Best practices and tips
  • Use terraform validate as a quick pre-commit or CI check to catch syntax/regression issues before running expensive plans.
  • Combine terraform validate with terraform fmt -check in CI to ensure consistent formatting and valid syntax.
  • Remember that validate is not a substitute for terraform plan — always review the plan before applying.
Exam tip
  • For the Terraform Associate exam and practical use, remember: terraform validate is an offline syntax/structure check and requires terraform init to have been run in the working directory.
Links and references

Watch Video