- Save latest
terraform-docspre-built binary into$PATHfrom terraform-docs GitHub Releases.terraform-docs --version # terraform-docs version v0.21.0 ... - Configure
.terraform-docs.ymlto updateREADME.mdappropriately. Usually this file would be saved in the root of the repo. If you have amodulesdirectory containing many modules with READMEs to update, you can add therecursiveargument. See.terraform-docs.ymloptions docs.# https://terraform-docs.io/user-guide/configuration/ formatter: markdown table output: file: README.md sections: show: - requirements - resources - inputs - outputs sort: enabled: true by: required # Recursive config for subdirectories with modules # https://terraform-docs.io/user-guide/configuration/recursive/ #recursive: # enabled: true # path: modules # include-main: true
- Ensure
terraform-docs .or a similar command from the root of the repository updatesREADME.mdfile(s) as desired. - Configure git pre-commit hook in file
.git/hooks/pre-commit. Git hooks run from the root of the repository, so specify relative paths from there. See Git hooks docs.#!/bin/sh # https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks echo "[Git hook: pre-commit] Updating README.md file(s) with terraform-docs" terraform-docs . git add README.md # Option for recursive module subdirectories #git add README.md '**/README.md'
- Update a variable, output, etc. and see the
README.mdupdate on commit:$ git commit -am 'Update variables documentation' [Git hook: pre-commit] Updating README.md file(s) with terraform-docs README.md updated successfully [main 8095528] Update variables documentation 2 files changed, 15 insertions(+), 17 deletions(-)
Last active
February 23, 2026 21:41
-
-
Save atheiman/2b56eb7b6942d7403bede7964d46680e to your computer and use it in GitHub Desktop.
Configure a terraform repo to update README.md with `terraform-docs` in a `pre-commit` Git hook
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment