Pre-commit Hooks¶
TerraTidy provides pre-commit hooks for local development.
Installation¶
Install pre-commit:
Configuration¶
Add to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/santosr2/TerraTidy
rev: v0.2.0-alpha.4
hooks:
- id: terratidy-fmt
- id: terratidy-style
- id: terratidy-lint
Available Hooks¶
| Hook ID | Description |
|---|---|
terratidy-fmt | Format Terraform files |
terratidy-fmt-check | Check formatting (no changes) |
terratidy-style | Check style issues |
terratidy-style-fix | Check and fix style issues |
terratidy-lint | Run linting checks |
terratidy-check | Run all checks |
terratidy-fix | Auto-fix all issues |
terratidy-policy | Run policy checks |
Examples¶
Minimal Setup¶
Format and lint checks:
repos:
- repo: https://github.com/santosr2/TerraTidy
rev: v0.2.0-alpha.4
hooks:
- id: terratidy-fmt
- id: terratidy-lint
Strict Setup¶
All checks with auto-fix:
CI-like Setup¶
Full checks without auto-fix:
repos:
- repo: https://github.com/santosr2/TerraTidy
rev: v0.2.0-alpha.4
hooks:
- id: terratidy-check
With Custom Config¶
repos:
- repo: https://github.com/santosr2/TerraTidy
rev: v0.2.0-alpha.4
hooks:
- id: terratidy-check
args: ['--config', '.terratidy-ci.yaml']
With Profile¶
repos:
- repo: https://github.com/santosr2/TerraTidy
rev: v0.2.0-alpha.4
hooks:
- id: terratidy-check
args: ['--profile', 'development']
Install Hooks¶
After adding configuration:
Manual Run¶
# Run on all files
pre-commit run --all-files
# Run specific hook
pre-commit run terratidy-lint --all-files
# Run on staged files
pre-commit run
Updating Hooks¶
Troubleshooting¶
Hook Not Found¶
Ensure TerraTidy is installed:
Slow Hooks¶
For large projects, use:
Or run full checks only in CI.