A fork of the sphinx-terraform extension.
Project description
sphinx-terraform-ch
A Sphinx extension that auto-generates documentation for Terraform modules directly from HCL source files.
Based on the original sphinx-terraform by Charles Bouchard-Légaré.
This fork (sphinx-terraform-ch) rewrites the extension with a new Sphinx domain, block renderer, and module parser.
Features
tfmoduledirective: auto-document one or more Terraform modules from a pathtf:Sphinx domain: manually document individual Terraform objects with cross-reference supporttfreportCLI: generate Markdown documentation from the command line- Supports all standard Terraform block types:
resource,variable,locals,data,terraform,module, 0. provider,check,import,removed- Extracts preceding HCL comments (
#,//,/* */) as block descriptions - Cross-module cross-referencing via
tf:projectnamespaces
Installation
pip install sphinx-terraform-ch
Or with uv:
uv add sphinx-terraform-ch
Configuration
Add the extension and MyST parser to your conf.py:
extensions = [
"sphinx_terraform_ch",
"myst_parser",
]
Usage
tfmodule Directive
The tfmodule directive scans a directory for .tf files and renders documentation for every block found.
.. tfmodule::
:path: ../terraform/modules
:submodules_depth: 1
:ignore: ["\.terraform", "examples"]
:hide_nocomment:
Options:
| Option | Description |
|---|---|
:path: |
Path to the Terraform module directory (required) |
:submodules_depth: |
How many directory levels deep to look for submodules (default: 0, meaning the path itself) |
:ignore: |
JSON array of regex patterns — subdirectories whose names match are skipped |
:hide_nocomment: |
Flag. If set, blocks without a preceding comment are omitted from output |
Example — document a single module:
.. tfmodule::
:path: ./terraform
Example — document all submodules one level deep, skipping test directories:
.. tfmodule::
:path: ./terraform/modules
:submodules_depth: 1
:ignore: ["test", "examples"]
Example — only show documented blocks:
.. tfmodule::
:path: ./terraform
:hide_nocomment:
tf: Domain Directives
You can manually document Terraform objects using the tf: domain. These support cross-referencing across your Sphinx project.
Supported directives:
.. tf:resource:: aws_instance web
.. tf:variable:: region
.. tf:locals::
.. tf:data:: aws_ami ubuntu
.. tf:module:: vpc
.. tf:provider:: aws
.. tf:terraform::
.. tf:check:: health
.. tf:import::
.. tf:removed::
Cross-reference roles:
| Role | Object Type |
|---|---|
:tf:res: |
resource |
:tf:var: |
variable |
:tf:local: |
locals |
:tf:data: |
data |
:tf:mod: |
module |
:tf:prov: |
provider |
:tf:tf: |
terraform |
:tf:check: |
check |
Example cross-reference:
See :tf:var:`region` and :tf:res:`aws_instance.web`.
tf:project Namespace
When documenting multiple modules, use tf:project to scope cross-references so that names do not collide across modules.
.. tf:project:: projectA
.. tf:variable:: region
See :tf:var:`region` (resolves within projectA).
.. tf:project:: None
The tfmodule directive sets this automatically for each module it renders.
tfreport CLI
tfreport generates Markdown documentation for a Terraform module from the command line.
usage: tfreport [-h] [--level LEVEL] [-v] path
Generate a Terraform documentation report for a module path.
positional arguments:
path Path to the Terraform module directory.
options:
--level LEVEL Heading level for the generated report (default: 1).
-v, --verbose Verbosity controls (repeat for more output: -v, -vv, -vvv).
Example:
tfreport ./terraform/modules/vpc
tfreport ./terraform/modules/vpc --level 2 -v
Output is Markdown printed to stdout, suitable for piping or redirecting into a file.
HCL Comment Support
Comments placed immediately before a block (no blank lines between) are extracted and used as the block description. All HCL comment styles are supported:
# This is a variable for the AWS region.
variable "region" {
type = string
default = "us-east-1"
}
// Multi-word resource description.
resource "aws_instance" "web" {
ami = "ami-12345"
instance_type = "t3.micro"
}
/*
* This locals block computes derived values.
*/
locals {
name_prefix = "myapp-${var.env}"
}
License
BSD-2-Clause-Patent. See LICENSE for details.
Original work copyright (c) 2022 Charles Bouchard-Légaré.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_terraform_ch-2026.4.28.3.tar.gz.
File metadata
- Download URL: sphinx_terraform_ch-2026.4.28.3.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26e13e03c4b7bf1aba3b682fc0f3354c62f8fa781aa0fe0609cdd4c8bc74dc61
|
|
| MD5 |
f7b044d861bd6d6ba02e6c492b3d18f5
|
|
| BLAKE2b-256 |
cf0497301868d06440ad632515d0e3cfa162b46e3369db17a03d9b604c1302bd
|
Provenance
The following attestation bundles were made for sphinx_terraform_ch-2026.4.28.3.tar.gz:
Publisher:
python-publish.yml on chalbersma/sphinx-terraform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_terraform_ch-2026.4.28.3.tar.gz -
Subject digest:
26e13e03c4b7bf1aba3b682fc0f3354c62f8fa781aa0fe0609cdd4c8bc74dc61 - Sigstore transparency entry: 1398143361
- Sigstore integration time:
-
Permalink:
chalbersma/sphinx-terraform@5e54c2b1d41f73733f8d3e746a633f754c0f71b3 -
Branch / Tag:
refs/tags/2024.04.28.3 - Owner: https://github.com/chalbersma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e54c2b1d41f73733f8d3e746a633f754c0f71b3 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sphinx_terraform_ch-2026.4.28.3-py3-none-any.whl.
File metadata
- Download URL: sphinx_terraform_ch-2026.4.28.3-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6507b9436022762c38aa64dab5621ace4d76c09f03b4a4af6f1509e62c888f5
|
|
| MD5 |
1859c0aa8cc7a94c65e986438529d5ee
|
|
| BLAKE2b-256 |
b769a07baacf31b7d53fd3b2bd16317fea5cd7763c54ec8b50aff771e9e2bbe7
|
Provenance
The following attestation bundles were made for sphinx_terraform_ch-2026.4.28.3-py3-none-any.whl:
Publisher:
python-publish.yml on chalbersma/sphinx-terraform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphinx_terraform_ch-2026.4.28.3-py3-none-any.whl -
Subject digest:
a6507b9436022762c38aa64dab5621ace4d76c09f03b4a4af6f1509e62c888f5 - Sigstore transparency entry: 1398143399
- Sigstore integration time:
-
Permalink:
chalbersma/sphinx-terraform@5e54c2b1d41f73733f8d3e746a633f754c0f71b3 -
Branch / Tag:
refs/tags/2024.04.28.3 - Owner: https://github.com/chalbersma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e54c2b1d41f73733f8d3e746a633f754c0f71b3 -
Trigger Event:
release
-
Statement type: