This repository contains pre-commit hook configurations for Terraform projects to ensure code quality and consistency.
Slide Available here
This repository is used for the Community Day AWS 2025 event. It provides a set of pre-commit hooks to maintain Terraform code quality and consistency across various projects. The hooks include formatting, documentation generation, linting, and security checks.
Before you begin, ensure you have the following installed:
- Git
- pre-commit
- Terraform
- terraform-docs (for documentation generation)
- Other optional tools based on your needs:
brew install pre-commit terraform-docs tflint trivy checkov infracost tfupdate minamijoyo/hcledit/hcledit jqInitialize your Git repository:
git init
git branch -M mainCreate the pre-commit configuration file:
cat <<EOF > .pre-commit-config.yaml
repos:
- repo: <https://github.com/antonbabenko/pre-commit-terraform>
rev: v1.96.3
hooks:
- id: terraform_fmt
- id: terraform_docs
args:
- --hook-config=--create-file-if-not-exist=true
EOFInstall the pre-commit hooks:
pre-commit install --install-hooksOnce installed, the hooks will run automatically on every commit. You can also run them manually:
Run all pre-commit hooks
pre-commit run --all-files
Or
pre-commit run --file filename.extensionRun specific hook
pre-commit run terraform_fmt --all-files