Maintainers
This provider plugin is maintained by the team at Cato.
Requirements
- Terraform 0.12.x
- Go 1.25.0 (to build the provider plugin)
Building The Provider
Clone repository to: $GOPATH/src/github.com/terraform-providers/terraform-provider-cato
git clone git@github.com:catonetworks/terraform-provider-cato.git $GOPATH/src/github.com/terraform-providers/terraform-provider-cato
Enter the provider directory and build the provider
cd $GOPATH/src/github.com/terraform-providers/terraform-provider-cato
make build
Using the Provider
Set the following 2 environment variables:
export TF_VAR_token="abcde12345abcde12345"
export TF_VAR_account_id="12345"
Optional retry configuration:
export CATO_RETRY_MAX="5"
export CATO_RETRY_WAIT_MIN_SECONDS="1"
export CATO_RETRY_WAIT_MAX_SECONDS="30"
Debugging GraphQL API Traffic
When Terraform debug logging is enabled, the provider logs each GraphQL API
request and response from the Cato SDK under the API Call debug message. The
log entry includes:
request: the GraphQL query, operation name, and variables sent to Cato
response: the raw GraphQL response body returned by Cato
trace_id: the Cato server trace ID when returned by the API
Example:
export TF_LOG=DEBUG
export TF_LOG_PATH=~/Downloads/cato_terraform_debug.log
terraform apply
For easier support handoff, set TF_API_DUMP_DIR to write each GraphQL call to
its own file:
export TF_API_DUMP_DIR=~/Downloads/cato_api_calls
terraform apply
Debug logs and dump files can contain sensitive configuration values. Remove API
tokens and other secrets before sharing them outside your trusted support path.
Sample terraform files can be found in the examples folder in this repository. You can initialize and run these terraform files with the following commands:
terraform init
terraform plan
terraform apply --auto-approve
Developing the Provider
If you wish to work on the provider, you'll first need Go installed on your machine (version 1.11+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.
To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.
make install
...
$GOPATH/bin/terraform-provider-cato
...
In order to test the provider, you can simply run make test.
make test
In order to run the full suite of Acceptance tests, run make testacc.
Note: Acceptance tests create real resources, and often cost money to run.
make testacc
Please refer to Running TF Provider Tests for more details
This guide explains how to create persistent Terraform helper aliases
on:
- macOS / Linux (bash or zsh)
- Windows PowerShell
- Windows Git Bash
macOS / Linux (bash or zsh)
1. Open your shell config file
Bash
nano ~/.bashrc
Zsh (default on macOS)
nano ~/.zshrc
2. Add the aliases
alias tf='terraform'
alias tfap='terraform apply --auto-approve'
alias tfapp='terraform apply --auto-approve -parallelism=1'
alias tfdap='terraform destroy --auto-approve'
alias tfdapp='terraform destroy --auto-approve -parallelism=1'
alias tfclear='rm -rf .terraform* && rm terraform.tfstate*'
alias tftestapp='terraform test -parallelism=1'
alias tfdocs="terraform-docs markdown . --output-file README.md"
alias tfdebugon="export TF_LOG=DEBUG && export TF_LOG_PATH=~/Downloads/error_log.txt"
alias tfdebugoff="unset TF_LOG && unset TF_LOG_PATH"
alias tffmt="terraform fmt -recursive"
3. Reload your shell
source ~/.bashrc
or
source ~/.zshrc
Your aliases are now persistent.
Windows -- PowerShell (Recommended)
PowerShell requires functions instead of bash-style aliases.
1. Open your PowerShell profile
notepad $PROFILE
If it does not exist:
New-Item -ItemType File -Path $PROFILE -Force
notepad $PROFILE
2. Add the functions
function tf { terraform @args }
function tfap { terraform apply --auto-approve @args }
function tfapp { terraform apply --auto-approve -parallelism=1 @args }
function tfdap { terraform destroy --auto-approve @args }
function tfdapp { terraform destroy --auto-approve -parallelism=1 @args }
function tfclear {
Remove-Item -Recurse -Force .terraform* -ErrorAction SilentlyContinue
Remove-Item -Force terraform.tfstate* -ErrorAction SilentlyContinue
}
function tftestapp { terraform test -parallelism=1 @args }
function tfdocs {
terraform-docs markdown . --output-file README.md
}
function tfdebugon {
$env:TF_LOG="DEBUG"
$env:TF_LOG_PATH="$HOME\tf_error_log.txt"
}
function tfdebugoff {
Remove-Item Env:TF_LOG -ErrorAction SilentlyContinue
Remove-Item Env:TF_LOG_PATH -ErrorAction SilentlyContinue
}
function tffmt {
terraform fmt -recursive
}
3. Restart PowerShell
Close and reopen your terminal to apply changes.
Your aliases are now persistent.
Windows -- Git Bash
If using Git Bash on Windows, follow the macOS/Linux instructions and
edit:
nano ~/.bashrc
Then reload:
source ~/.bashrc
Verification
Test with:
tf --version
tfap
If Terraform runs, your aliases are working.