The thothctl document iac command generates comprehensive documentation for Infrastructure as Code (IaC) resources. It supports multiple IaC frameworks including Terraform and Terragrunt, helping teams maintain clear and up-to-date documentation for their infrastructure code.
thothctl document iac [OPTIONS]
| Option | Description |
|---|---|
--recursive / --no-recursive |
Generate documentation recursively for all modules/components |
--exclude TEXT |
Patterns to exclude from recursive generation |
--config-file PATH |
Custom terraform-docs configuration file |
--suffix TEXT |
Suffix for project root path (terragrunt only) |
--mood [resources\|modules] |
Type of documentation to generate |
-f, --framework [terraform\|terragrunt\|terraform-terragrunt] |
Type of IaC framework to document (required) |
--graph-type [dot\|mermaid] |
Type of dependency graph to generate (terragrunt only, default: dot) |
--help |
Show help message and exit |
Terraform is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure.
# Generate documentation for a Terraform module
thothctl document iac -f terraform
# Generate documentation recursively for all Terraform modules
thothctl document iac -f terraform --recursive
Terragrunt is a thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules.
# Generate documentation for a Terragrunt project
thothctl document iac -f terragrunt
# Generate documentation recursively for all Terragrunt modules
thothctl document iac -f terragrunt --recursive
Terragrunt projects support automatic dependency graph generation to visualize module relationships.
SVG Graph (Default):
# Generate SVG dependency graph
thothctl document iac -f terragrunt --graph-type dot
Output: graph.svg - Interactive SVG diagram showing module dependencies
Mermaid Graph:
# Generate Mermaid dependency graph
thothctl document iac -f terragrunt --graph-type mermaid
Output: graph.mmd - Text-based Mermaid diagram with:
mock_outputsExample Mermaid Output:
%%{init: {'theme':'base', 'themeVariables': {...}}}%%
graph LR
vpc["<b>vpc</b>"]:::rootNode
sg["<b>security-groups</b><br/><small>π₯ vpc: vpc_id, subnet_ids</small>"]:::normalNode
app["<b>app</b><br/><small>π₯ vpc: vpc_id<br/>π₯ sg: sg_id</small>"]:::normalNode
sg -->|vpc_id, subnet_ids| vpc
app -->|vpc_id| vpc
app -->|sg_id| sg
classDef rootNode fill:#4caf50,stroke:#2e7d32,stroke-width:3px,color:#fff
classDef normalNode fill:#2196f3,stroke:#1565c0,stroke-width:2px,color:#fff
classDef complexNode fill:#ff9800,stroke:#e65100,stroke-width:2px,color:#fff
Mermaid Benefits:
This option generates documentation for projects that use both Terraform and Terragrunt together.
# Generate documentation for a mixed Terraform-Terragrunt project
thothctl document iac -f terraform-terragrunt
Generate documentation focused on the resources defined in your IaC code.
# Generate resources documentation
thothctl document iac -f terraform --mood resources
Generate documentation focused on the modules used in your IaC code.
# Generate modules documentation
thothctl document iac -f terraform --mood modules
The --recursive flag allows you to generate documentation for all modules or components in a project, including nested ones.
# Generate documentation recursively
thothctl document iac -f terraform --recursive
# Exclude certain patterns when generating recursively
thothctl document iac -f terraform --recursive --exclude "**/.terraform/**" --exclude "**/examples/**"
You can provide a custom configuration file for terraform-docs to customize the generated documentation.
# Use a custom configuration file
thothctl document iac -f terraform --config-file ./terraform-docs.yml
Example terraform-docs.yml configuration:
formatter: markdown table
header-from: main.tf
footer-from: ""
sections:
hide: []
show: []
content: |-
## Usage
Basic usage example:
```hcl
module "example" {
source = "path/to/module"
// Required variables
region = "us-west-2"
// Optional variables
environment = "dev"
}
output: file: βREADME.mdβ mode: replace
## Output Examples
### Terraform Module Documentation
The generated documentation for a Terraform module typically includes:
- Module description and usage examples
- Required providers and their versions
- Input variables with descriptions, types, and default values
- Output values with descriptions
- Resources created by the module
- Submodules used by the module
### Terragrunt Project Documentation
The generated documentation for a Terragrunt project typically includes:
- Project structure and organization
- Module dependencies and relationships
- Input variables and their sources
- Generated Terraform configurations
## Integration with Version Control
You can integrate the document command with your version control workflow to ensure documentation is always up-to-date:
```bash
# Pre-commit hook example
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
echo "Updating documentation..."
thothctl document iac -f terraform --recursive
git add README.md **/README.md
EOF
chmod +x .git/hooks/pre-commit
You can also integrate the document command into your CI/CD pipeline:
# GitHub Actions example
name: Update Documentation
on:
push:
branches: [ main ]
paths:
- '**.tf'
- '**.hcl'
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install ThothCTL
run: pip install thothctl
- name: Generate Documentation
run: thothctl document iac -f terraform --recursive
- name: Commit updated documentation
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "docs: Update generated documentation"
file_pattern: "README.md **/README.md"
Structure:
stacks/
βββ vpc/
β βββ terragrunt.hcl
βββ security-groups/
βββ terragrunt.hcl (depends on vpc)
Command:
cd stacks
thothctl document iac -f terragrunt --graph-type mermaid
Result (graph.mmd):
graph LR
vpc["<b>vpc</b>"]:::rootNode
security_groups["<b>security-groups</b><br/><small>π₯ vpc: vpc_id, subnet_ids</small>"]:::normalNode
security_groups -->|vpc_id, subnet_ids| vpc
Structure:
stacks/
βββ vpc/
βββ rds/ (depends on vpc)
βββ security-groups/ (depends on vpc)
βββ app/ (depends on vpc, rds, security-groups)
Command:
cd stacks
thothctl document iac -f terragrunt --graph-type mermaid
Result: Multi-level dependency graph with color-coded complexity
When running from a subdirectory, the graph shows relative paths:
cd stacks/app
thothctl document iac -f terragrunt --graph-type mermaid
Result: Shows app and its dependencies like ..vpc, ..rds