After https://github.com/melmorabity/pre-commit-terraform-fmt
A pre-commit hook to rewrite Terraform / OpenTofu configuration files to a canonical format.
The hook auto-detects the binary: it prefers tofu (OpenTofu) if found on PATH, otherwise falls back to terraform. Matches .tf, .tfvars, .tofu and .tofuvars files. Use tofu-fmt or terraform-fmt as the hook id — both run the same implementation.
.pre-commit-config.yaml:
- repo: git://github.com/jameswoolfenden/pre-commit
rev: 0.0.1
hooks:
- id: tofu-fmt
# Optional: pin a specific binary
# args: [--terraform=/usr/local/bin/tofu]This runs the Static analysis tool https://www.checkov.io/ for Terraform, the hook automatically installs the Checkov tool.
For Checkov-scan:
- repo: git://github.com/jameswoolfenden/pre-commit
rev: 0.0.18
hooks:
- id: checkov-scan
files: \.tf$Updates README.md with Terraform parameters, modules. Requires:
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
The Hook will update in-betweeen with the Terraform-Docs created content. The hook requires that terraform-docs be installed, then add a section to you pre-commit-config.yml, updating to the latest version :
- repo: git://github.com/jameswoolfenden/pre-commit
rev: 0.0.22
hooks:
- id: tf2docs
