Install the Terraform policy CLI
The Terraform policy command-line interface, tfpolicy, tests and validates policies locally. Testing your policies helps you to identify errors when you write and update your policies, before you enforce them against your Terraform workspaces. Install the tfpolicy command on your local system before you author your policies and policy tests.
Installation
To install tfpolicy, visit the HashiCorp releases website to download the appropriate binary for your operating system and download it as a zip archive.
After you download tfpolicy, unzip the archive.
Finally, make sure that the tfpolicy binary is available in a directory that is in your system's PATH.
Every build of tfpolicy includes a SHA256SUMS and a SHA256SUMS.sig file to validate your downloaded binary. Refer to the verify HashiCorp binary downloads tutorial for more information.
Verify installation
Verify that the installation worked by opening a new terminal and using the --help flag of tfpolicy:
$ tfpolicy --help
Usage: tfpolicy [--version] [--help] <command> [<args>]
Available commands are:
test Test Terraform Policy files.
validate Validate Terraform policies configuration files.
version Prints the tfpolicy version
Usage
To begin writing policies, refer to Terraform policy - Write policies.
Reference
The tfpolicy CLI provides the following commands:
tfpolicy test: Run policy tests.tfpolicy validate: Validate policy syntax.