Command: validate

The terraform 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.

It is safe to run this command automatically, for example as a post-save check in a text editor or as a test step for a re-usable module in a CI system.

Validation requires an initialized working directory with any referenced plugins and modules installed. To initialize a working directory for validation without accessing any configured backend, use:

$ terraform init -backend=false

To verify configuration in the context of a particular run (a particular target workspace, input variable values, etc), use the terraform plan command instead, which includes an implied validation check.

Usage

Usage: terraform validate [options]

This command accepts the following options:

JSON Output Format

When you use the -json option, Terraform will produce validation results in JSON format to allow using the validation result for tool integrations, such as highlighting errors in a text editor.

As with all JSON output options, it's possible that Terraform will encounter an error prior to beginning the validation task that will thus not be subject to the JSON output setting. For that reason, external software consuming Terraform's output should be prepared to find data on stdout that isn't valid JSON, which it should then treat as a generic error case.

The output includes a format_version key, which as of Terraform 1.1.0 has value "1.0". The semantics of this version are:

We will introduce new major versions only within the bounds of the Terraform 1.0 Compatibility Promises.

In the normal case, Terraform will print a JSON object to the standard output stream. The top-level JSON object will have the following properties:

The nested objects in diagnostics have the following properties:

Source Position

A source position object, as used in the range property of a diagnostic object, has the following properties:

A start position is inclusive while an end position is exclusive. The exact positions used for particular error messages are intended for human interpretation only.

Expression Value

An expression value object gives additional information about a value which is part of the expression which triggered the diagnostic. This is especially useful when using for_each or similar constructs, in order to identify exactly which values are responsible for an error. The object has two properties: