explaingit

antonbabenko/pre-commit-terraform

Analysis updated 2026-07-03

3,711ShellAudience · ops devopsComplexity · 3/5Setup · moderate

TLDR

A set of automatic checks that run before every Git commit on Terraform files, catching formatting issues, syntax errors, security problems, and outdated docs before code is saved.

Mindmap

mindmap
  root((pre-commit-terraform))
    What it does
      Runs checks before commit
      Blocks bad code
      Auto-generates docs
    Hook types
      Formatting
      Syntax validation
      Security scanning
      Cost estimation
    Supported tools
      Terraform
      OpenTofu
      Terragrunt
    How to use
      Add config file
      Run setup command
      Use Docker image
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Block Terraform commits that have formatting or syntax errors without manually running checks

USE CASE 2

Automatically regenerate Terraform module documentation every time code changes

USE CASE 3

Scan infrastructure-as-code for security vulnerabilities before code is merged

USE CASE 4

Estimate cloud cost changes caused by a pull request using infracost before it ships

What is it built with?

ShellTerraformDockerPython

How does it compare?

antonbabenko/pre-commit-terraformarialdomartini/oh-my-gitolegos2/mobox
Stars3,7113,7093,700
LanguageShellShellShell
Setup difficultymoderatemoderatehard
Complexity3/52/54/5
Audienceops devopsdevelopergeneral

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 30min

Requires pre-commit framework installed plus individual tools (tflint, terraform-docs, etc.) or the bundled Docker image.

Not specified in the explanation.

In plain English

Pre-commit-terraform is a collection of Git hooks designed to automatically check and format Terraform configuration files before you commit code. Terraform is a tool used to define and manage cloud infrastructure by writing configuration files. A Git hook is a script that runs automatically at a certain point in the version control process, for example right before you save a new commit. The pre-commit framework is a system that manages and runs these hooks across multiple languages and tools. When you set this up in a project, it runs a series of checks every time a developer commits. The checks cover formatting so that all Terraform files follow a consistent style, validation to catch syntax errors and configuration mistakes, security scanning to flag potential vulnerabilities in the infrastructure definitions, and documentation generation to keep module documentation up to date automatically. If any check fails, the commit is blocked until the issue is fixed. The hooks support Terraform, OpenTofu (an open-source fork of Terraform), and Terragrunt. You can run them locally on your own machine before pushing code, or in a continuous integration pipeline so every pull request is checked automatically. A Docker image is provided that bundles all the supported tools together, which avoids the need to install each tool individually on every developer's machine. Specific hooks include terraform-fmt for formatting, terraform-validate for syntax checking, terraform-docs for updating documentation from code, tflint for deeper linting rules, trivy and checkov for security scanning, infracost for estimating cloud spending changes, and tfupdate for keeping provider version references current. Many hooks can run in parallel to keep the overall check time short. Installation involves adding a configuration file to your repository that lists which hooks you want, then running one setup command. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
I have a Terraform project and want to block commits that have formatting errors or syntax mistakes. Set up pre-commit-terraform with the terraform-fmt and terraform-validate hooks in my repo.
Prompt 2
Show me how to add a security scanning hook using trivy or checkov to my pre-commit-terraform config so every commit is checked for infrastructure vulnerabilities.
Prompt 3
I want to automatically update my Terraform module README every time I change the module. Walk me through setting up the terraform-docs hook with pre-commit-terraform.
Prompt 4
How do I run pre-commit-terraform hooks inside a CI pipeline like GitHub Actions so every pull request is validated automatically?
Prompt 5
Set up infracost with pre-commit-terraform so I get a cloud cost estimate every time I commit a Terraform change.

Frequently asked questions

What is pre-commit-terraform?

A set of automatic checks that run before every Git commit on Terraform files, catching formatting issues, syntax errors, security problems, and outdated docs before code is saved.

What language is pre-commit-terraform written in?

Mainly Shell. The stack also includes Shell, Terraform, Docker.

What license does pre-commit-terraform use?

Not specified in the explanation.

How hard is pre-commit-terraform to set up?

Setup difficulty is rated moderate, with roughly 30min to a first successful run.

Who is pre-commit-terraform for?

Mainly ops devops.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub antonbabenko on gitmyhub

Verify against the repo before relying on details.