Validating Configuration
terraform validate checks configuration without contacting any remote system. This lesson explains what it catches, what it misses and how it is used.
Learning outcomes
After completing this lesson, you will be able to:
- Explain what terraform validate checks and what it cannot check.
- Describe how validate is used in development and CI.
What validate checks
terraform validate parses every .tf file in the working directory and checks that the configuration is syntactically valid and internally consistent. It catches errors such as a missing closing brace, an argument name that the provider's schema does not define, a missing required argument, a value of the wrong type, and a reference to a variable, resource or module that does not exist.
$ terraform validate
Error: Reference to undeclared input variable
on main.tf line 4, in resource "local_file" "motd":
4: content = var.mesage
An input variable with the name "mesage" has not been declared. Did you mean "message"?Because validate checks argument names and types against provider schemas, the providers must be installed, so run terraform init first. In environments without backend access, terraform init -backend=false installs providers and modules without configuring the backend.
Caught by validate?
What validate does not check
validate never reads state and never calls provider APIs. It therefore cannot know whether an image ID exists, whether a bucket name is already taken, whether credentials work or whether the configuration would change anything. Those problems surface in plan or apply.
The following diagram shows where a value that is valid syntax but wrong for the provider is caught.

Using validate in development and CI
Editors and pre-commit hooks run validate to give feedback in seconds. In continuous integration, a check stage typically runs these commands before any plan, so broken code fails quickly and without credentials.
terraform fmt -check -recursive
terraform init -backend=false -input=false
terraform validateterraform validate -json produces machine-readable diagnostics for tools. Plan and apply validate the configuration themselves, so validate is about speed and early feedback, not an additional safety check.
A CI check stage
Valid but wrong
A configuration sets ami = "ami-12345678" on an aws_instance, but that image does not exist in the region. terraform validate reports "Success! The configuration is valid." Why?
The decisive fact is that validate is offline.
The value is a string, which is the correct type, and the argument name is correct, so the configuration is internally consistent. Whether the image exists can only be discovered by calling the AWS API, which validate never does. The error appears during terraform apply, when the provider tries to launch the instance. A data source that looks up the image, or a precondition, would catch it during plan.
Can terraform validate detect that a referenced image ID does not exist?
Show answer
No. validate is offline: it checks syntax and internal consistency but never calls provider APIs.
Exam Tips
Remember for the exam
- validate checks syntax and consistency only, offline.
- Run init (optionally -backend=false) before validate.
- validate cannot detect missing images, taken names or bad credentials.