Module 3: Core Terraform Workflow

Lesson 3.3: Validating a Configuration

Plain language

terraform validate checks that your configuration is syntactically valid and internally consistent.

Under the hood

validate checks validate does not check
HCL syntax Whether credentials work
Correct block types and argument names, using provider schemas Whether a referenced remote object exists (an AMI, a subnet)
Required arguments are present API quotas, permissions, naming collisions
References point to declared objects Variable values from .tfvars files (validation runs without them)
Type consistency where values are known State or drift

Two more points:

  • validate requires init, because it needs the provider schemas. In a fresh directory it errors and tells you to run terraform init.
  • terraform validate -json produces machine-readable results for CI.