Home

Awesome

terraform-docs GitHub Actions

Generate Terraform module documentation in pull requests.

In addition to statically defined directory modules, this module can search specific subfolders or parse atlantis.yaml for module identification and doc generation. This action has the ability to auto commit docs to an open PR or after a push to a specific branch.

Version

v1.3.0 (uses terraform-docs v0.19.0, which is supported and tested on Terraform version 0.11+ and 0.12+ but may work for others.)

Upgrade v0 to v1

Release v1 contains following breaking changes:

Usage

To use terraform-docs github action, configure a YAML workflow file, e.g. .github/workflows/documentation.yml, with the following:

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 inside the README.md and push changes back to PR branch
      uses: terraform-docs/gh-actions@v1.3.0
      with:
        working-dir: .
        output-file: README.md
        output-method: inject
        git-push: "true"
NOTE: If output-file (default README.md) already exists it will need to be updated, with the block delimeters <!-- BEGIN_TF_DOCS --> and <!-- END_TF_DOCS -->, where the generated markdown will be injected. Otherwise the generated content will be appended at the end of the file.
NOTE: If output-file (default README.md) doesn't exist it will created and the content will be saved into it.

Configuration

Inputs

NameDescriptionDefaultRequired
argsAdditional arguments to pass to the command (see full documentation)""false
atlantis-fileName of Atlantis file to extract list of directories by parsing it. To enable, provide the file name (e.g. atlantis.yaml)disabledfalse
config-fileName of terraform-docs config file. To enable, provide the file name (e.g. .terraform-docs.yml)disabledfalse
fail-on-diffFail the job if there is any diff found between the generated output and existing file (ignored if git-push is set)falsefalse
find-dirName of root directory to extract list of directories by running find ./find\_dir -name \*.tf (ignored if atlantis-file is set)disabledfalse
git-commit-messageCommit messageterraform-docs: automated actionfalse
git-pushIf true it will commit and push the changesfalsefalse
git-push-sign-offIf true it will sign-off commitfalsefalse
git-push-user-emailIf empty the no-reply email of the GitHub Actions bot will be used (i.e. github-actions[bot]@users.noreply.github.com)""false
git-push-user-nameIf empty the name of the GitHub Actions bot will be used (i.e. github-actions[bot])""false
git-sub-dirSubdirectory that terraform code is checked out into""false
indentionIndention level of Markdown sections [1, 2, 3, 4, 5]2false
output-fileFile in module directory where the docs should be placedREADME.mdfalse
output-formatterraform-docs format to generate content (see all formats) (ignored if config-file is set)markdown tablefalse
output-methodMethod should be one of replace, inject, or print. Set as an empty string if output.mode and output.file are defined in config-fileinjectfalse
recursiveIf true it will update submodules recursivelyfalsefalse
recursive-pathSubmodules path to recursively updatemodulesfalse
templateWhen provided will be used as the template if/when the output-file does not exist. Set as an empty string if output.template is defined in config-file<!-- BEGIN_TF_DOCS -->\n{{ .Content }}\n<!-- END_TF_DOCS -->false
working-dirComma separated list of directories to generate docs for (ignored if atlantis-file or find-dir is set).false

Output Method (output-method)

Auto commit changes

To enable you need to ensure a few things first:

Outputs

NameDescription
num_changedNumber of files changed

Examples

Single folder

- name: Generate TF Docs
  uses: terraform-docs/gh-actions@v1.3.0
  with:
    working-dir: .

Multi folder

- name: Generate TF Docs
  uses: terraform-docs/gh-actions@v1.3.0
  with:
    working-dir: .,example1,example3/modules/test

Use atlantis.yaml v3 to find all directories

- name: Generate TF docs
  uses: terraform-docs/gh-actions@v1.3.0
  with:
    atlantis-file: atlantis.yaml

Find all .tf file under a given directory

- name: Generate TF docs
  uses: terraform-docs/gh-actions@v1.3.0
  with:
    find-dir: examples/

Recursively under a given directory

- name: Generate TF docs
  uses: terraform-docs/gh-actions@v1.3.0
  with:
    working-dir: examples/
    recursive: true
    recursive-path: modules

Complete examples can be found here.