- Terraform Policy
- v0.2.x (latest)
- v0.1.x (beta)
tfpolicy validate
The tfpolicy validate command validates the syntax of your policy files.
Usage
$ tfpolicy validate --policies=</path/to/policies>
Description
Once you have written your .policy.hcl files, validate their syntax with the tfpolicy validate command. Similar to the terraform validate command, tfpolicy validate reports whether your policies are syntactically valid and internally consistent.
The required_providers block is mandatory for policy files that contain resource or provider policies. Terraform policy uses this configuration when validating your provider, resource, and data source policy attributes, as well as the arguments to the core::getdatasource and core::getresources functions against the schemas of the providers specified. Policies that match multiple resource types with * must validate against each matching resource or data source type that matches the expression. For more information, refer to required_providers.
Available options
The tfpolicy validate command supports the following options.
| Option | Description | Default | Required |
|---|---|---|---|
--policies=</path/to/policies> | Validate the syntax of all policies found in the specified path. | Current directory | No |
--evaluation-stage=<stage> | Validate policies for the specified evaluation stage: "setup" or "plan". | "plan" | No |
Exit code
The tfpolicy validate command exits with either a non-zero exit code when any validation fails or an exit code of 0 if validation is successful.
Examples
The following examples demonstrate the tfpolicy validate command.
Basic usage
Validate the syntax of all policies in the current directory:
$ tfpolicy validate --policies=.
Success! Terraform policies validated successfully.
Validate the syntax of all policies in the specified directory:
$ tfpolicy validate --policies=./policies