Terraform Docs

Terraform-docs is a utility for generating documentation from Terraform modules in various output formats.

Installation

Using Homebrew

brew install terraform-docs

Using Go

go install github.com/terraform-docs/terraform-docs@latest

Docker

docker pull quay.io/terraform-docs/terraform-docs:latest

Usage

Basic Command

terraform-docs markdown table /path/to/module

Configuration File

Create .terraform-docs.yml in your module directory:

Integration with Git Hooks

Add to .git/hooks/pre-commit:

CI/CD Integration

GitHub Actions

Azure DevOps Pipeline

Output Formats

  1. Markdown Table (default)

  1. Markdown Document

  1. JSON

  1. YAML

Best Practices

  1. Documentation Comments

  2. Required vs Optional

  3. Examples in Description

Common Issues and Solutions

  1. Missing Documentation

    • Ensure all variables and outputs have descriptions

    • Use meaningful names for resources

    • Include examples where appropriate

  2. Version Conflicts

    • Keep terraform-docs updated

    • Pin version in CI/CD pipelines

    • Check compatibility with Terraform version

  3. Output Formatting

    • Use consistent formatting

    • Follow team conventions

    • Include all necessary sections

Checklist

Last updated