Terraform-docs
Installation:
Linux:
bash
brew install terraform-docs/tap/terraform-docs
plaintext
Windows:
powershell
scoop bucket add terraform-docs https://github.com/terraform-docs/scoop-bucket
scoop install terraform-docs
plaintext
powershell
choco install terraform-docs
plaintext
Docker/Podman
bash
/docker run --rm --volume "$(pwd):/terraform-docs" -u $(id -u) quay.io/terraform-docs/terraform-docs:0.16.0 markdown /terraform-docs
plaintext
GitHub Actions:
```yaml /name: Generate terraform docs on:
- pull_request
jobs: docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: ref: ${{ github.event.pull_request.head.ref }}
- name: Render terraform docs and push changes back to PR
uses: terraform-docs/gh-actions@main
with:
working-dir: .
output-file: README.md
output-method: inject
git-push: "true" ```plaintext
pre-commit hook
With pre-commit, you can ensure your Terraform module documentation is kept up-to-date each time you make a commit.
```yaml repos:
- repo: https://github.com/terraform-docs/terraform-docs
rev: βv0.16.0β
hooks:
- id: terraform-docs-go args: [βmarkdownβ, βtableβ, ββoutput-fileβ, βREADME.mdβ, β./mymodule/pathβ] ```plaintext
Configuration
terraform-docs can be configured with a yaml file. The default name of this file is .terraform-docs.yml and the path order for locating it is:
- root of module directory
.config/folder at root of module directory- current directory
.config/folder at current directory$HOME/.tfdocs.d/
```yaml formatter: ββ # this is required
version: ββ
header-from: main.tf footer-from: ββ
recursive: enabled: false path: modules
sections: hide: [] show: []
content: ββ
output: file: ββ mode: inject template: |- {{ .Content }}
output-values: enabled: false from: ββ
sort: enabled: true by: name
settings: anchor: true color: true default: true description: false escape: true hide-empty: false html: true indent: 2 lockfile: true read-comments: true required: true sensitive: true type: trueaml ```plaintext