Discover and explore top open-source AI tools and projects—updated daily.
Collection of Git hooks for Terraform using pre-commit framework
Top 13.7% on SourcePulse
This repository provides a collection of pre-commit Git hooks designed to automate the validation, formatting, and documentation of Terraform, OpenTofu, and Terragrunt configurations. It targets infrastructure engineers and DevOps professionals seeking to enforce code quality and consistency within their IaC workflows.
How It Works
The project leverages the pre-commit
framework to integrate various static analysis and formatting tools directly into the Git commit process. It supports Terraform and Terragrunt files, offering hooks for linting (TFLint, TFSec, Trivy, Checkov), formatting (terraform fmt
, terragrunt fmt
), documentation generation (terraform-docs
), and dependency management (terraform_providers_lock
, terragrunt_providers_lock
). The hooks can be run locally or within CI environments, either as standalone Git hooks or via a Docker image.
Quick Start & Requirements
.pre-commit-config.yaml
.git
, pre-commit
, terraform
or opentofu
, bash 3.2.57+
. Many hooks require additional tools like checkov
, terraform-docs
, tflint
, tfsec
, trivy
, terrascan
, infracost
, tfupdate
, hcledit
, and jq
.docker pull ghcr.io/antonbabenko/pre-commit-terraform:latest
or build from source.pre-commit
and potentially individual tools or building the Docker image. Configuration involves creating a .pre-commit-config.yaml
file.Highlighted Details
Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
The terraform_validate
hook may error with Terraform 0.15+ provider configuration aliases; workarounds are provided. Some hooks might be slow depending on repository size and machine resources. The README notes that checkov
and terraform_tfsec
hooks are deprecated in favor of terraform_checkov
and terraform_trivy
respectively.
2 days ago
1 day