Synopsis
Check whether the configuration is validDescription
Theterraform validate command validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc.
Validate runs checks that verify whether a configuration is syntactically valid and internally consistent, regardless of any provided variables or existing state. It is thus primarily useful for general verification of reusable modules, including correctness of attribute names and value types.
This command is safe to run automatically, for example as a post-save check in a text editor or as a test step for a reusable module in a CI system.
Important: Validation requires an initialized working directory with any referenced plugins and modules installed. To initialize a working directory for validation without accessing any configured remote backend, use:
terraform plan command instead, which includes an implied validation check.
Usage
Arguments
The directory containing the Terraform configuration to validate. Defaults to the current directory.
Options
Produce output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems. Always disables color.
If specified, output won’t contain any color.
If specified, Terraform will not validate test files.
Set the Terraform test directory, defaults to “tests”.
If specified, the command will also validate .tfquery.hcl files.
Examples
Basic Validation
Validate configuration in the current directory:Validation with Errors
Example output when configuration has errors:JSON Output
Validate with JSON output for tooling integration:Validate Specific Directory
Validate configuration in a specific directory:Exclude Test Files
Validate without checking test files:Exit Codes
0- Success, configuration is valid1- Error occurred, configuration is invalid