pre-commit-terraform  by antonbabenko

Collection of Git hooks for Terraform using pre-commit framework

Created 9 years ago
3,541 stars

Top 13.7% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

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

  • Install: Add the repository to your .pre-commit-config.yaml.
  • Prerequisites: 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: docker pull ghcr.io/antonbabenko/pre-commit-terraform:latest or build from source.
  • Setup: Requires installing pre-commit and potentially individual tools or building the Docker image. Configuration involves creating a .pre-commit-config.yaml file.
  • Docs: https://github.com/antonbabenko/pre-commit-terraform

Highlighted Details

  • Supports Terraform, OpenTofu, and Terragrunt.
  • Extensive hook selection for security, formatting, and documentation.
  • Customizable hook arguments and environment variables.
  • Docker image available for consistent execution.
  • Supports custom Terraform binary paths, including OpenTofu.

Maintenance & Community

  • Maintained by Anton Babenko.
  • Open to contributions and sponsorships.
  • Links to issues and contribution notes are provided.

Licensing & Compatibility

  • MIT licensed.
  • Compatible with commercial use and closed-source linking.

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.

Health Check
Last Commit

2 days ago

Responsiveness

1 day

Pull Requests (30d)
5
Issues (30d)
3
Star History
30 stars in the last 30 days

Explore Similar Projects

Starred by David Cournapeau David Cournapeau(Author of scikit-learn), Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), and
7 more.

repomix by yamadashy

0.6%
19k
CLI tool to pack codebases into AI-friendly formats for LLMs
Created 1 year ago
Updated 2 days ago
Feedback? Help us improve.