A simple, fast CLI tool for generating terminal and PNG visualizations of your Terraform infrastructure.
Project description
terraform-viz - Terraform Infrastructure Visualizer
A simple, fast CLI tool for generating PNG visualizations of your Terraform infrastructure.
Overview
terraform-viz generates visual diagrams showing your Terraform resources, their dependencies, and relationships. Output to terminal by default for quick review, or generate PNG images for documentation.
Features
- ๐บ Terminal output - Rich-formatted diagrams for quick review and CI/CD (default)
- ๐จ PNG generation - High-quality images for documentation (with
-oflag) - ๐ Flexible paths - Work with any Terraform directory
- ๐ฆ Plan support - Visualize specific plan files
- ๐งน Clean operation - Optional intermediate file cleanup
- ๐ฌ Verbose mode - Detailed progress information
- ๐ฏ Custom spacing - Adjustable node padding for PNG layouts
Installation
From PyPI (Recommended)
pip install terraform-viz
# or
uv add terraform-viz
From Source
git clone https://github.com/pedropcamellon/terraform-viz.git
cd terraform-viz
uv pip install -e .
Prerequisites
- Terraform - Must be available in PATH or specify path with
--tf-path - Graphviz - Only required for PNG images (with
-oflag)- Install:
winget install graphviz(Windows) orbrew install graphviz(macOS)
- Install:
Usage
Quick Start
# Basic usage - shows diagram in terminal
terraform-viz
# Generate PNG image for documentation
terraform-viz -o infrastructure.png
# Work with different Terraform directory
terraform-viz --tf-dir ../production
# Visualize a specific plan file
terraform-viz --plan-file tfplan
# Specify custom Terraform executable
terraform-viz --tf-path /path/to/terraform
# Verbose output with intermediate files kept
terraform-viz -v --keep-dot
# Adjust spacing between nodes (PNG only)
terraform-viz -o output.png --node-padding 1.5
Command Line Options
usage: terraform-viz [-h] [-o OUTPUT] [--tf-dir TF_DIR] [--tf-path TF_PATH]
[--keep-dot] [--verbose] [--node-padding NODE_PADDING]
[--plan-file PLAN_FILE]
Generate visualizations of Terraform infrastructure (terminal output by default, PNG with -o)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Generate PNG image (default: terminal output only)
--tf-dir TF_DIR Directory containing Terraform files (default: current directory)
--tf-path TF_PATH Path to Terraform executable or alias (default: terraform)
--keep-dot Keep intermediate DOT file after rendering
--verbose, -v Enable verbose output
--node-padding NODE_PADDING
Spacing between nodes for PNG output (default: 1.0, larger = more spaced out)
--plan-file PLAN_FILE
Path to Terraform plan file to visualize (optional)
How It Works
- Discovery - Locates Terraform executable (and Graphviz if generating PNG)
- Graph Generation - Runs
terraform graphto create DOT format dependency graph - Rendering - Displays ASCII diagram in terminal (default) or generates PNG with
-oflag - Cleanup - Optionally removes intermediate DOT file
Understanding the Output
Modules vs Resources
Resources are the actual infrastructure components you're creating:
- Direct resources in your root Terraform configuration
- Examples:
azurerm_storage_account.main,aws_instance.web,random_string.suffix - These are the "real" things that get created in your cloud provider
Modules are reusable packages of Terraform configurations:
- Contain multiple resources bundled together
- Prefixed with
module.in the graph (e.g.,module.storage.azurerm_storage_account.this) - Help organize and reuse infrastructure patterns
- Each module creates its own set of resources
Reading the Hierarchy
The terminal output shows a parent โ child dependency tree:
- Parent at top: Resources that others depend on
- Children nested below: Resources that depend on the parent
- Multiple appearances: A resource may appear multiple times if it has dependencies on different parents
Example:
๐๏ธ azurerm_resource_group.mini (parent)
โโโ ๐ cosmos_db.azurerm_cosmosdb_account.this (child)
โ โโโ ๐ฆ azurerm_linux_web_app.backend (grandchild)
This means:
- The web app depends on the Cosmos DB account
- The Cosmos DB account depends on the resource group
- All must be created in order: resource group โ database โ web app
Example:
module.storage.azurerm_storage_account.this โ Module resource (inside "storage" module)
azurerm_resource_group.main โ Root resource (in your main config)
ASCII Output (Default)
The ASCII diagram shows:
- ๐ฅ Variables - Input variables
- ๐ Providers - Cloud/infrastructure providers
- ๐ Data Sources - External data being fetched
- ๐ Modules - Terraform modules
- ๐ฆ Resources - Terraform resources
- ๐ค Outputs - Output values
- โโโบ - Dependencies between resources
PNG Output (with -o flag)
The generated PNG shows:
- Resources - Terraform resources (rectangles)
- Data Sources - External data being fetched (diamonds)
- Variables - Input variables (ovals)
- Outputs - Output values (house shapes)
- Dependencies - Arrows showing resource relationships
Both formats help you:
- Understand resource dependencies
- Identify circular dependencies
- Visualize infrastructure complexity
- Document your architecture
Troubleshooting
Common Issues
Terraform not found:
- Check if Terraform is in PATH:
where terraform(Windows) orwhich terraform(macOS/Linux) - Install Terraform or ensure it's in your PATH
Graphviz not found (only for PNG generation):
- Check if Graphviz is in PATH:
where dot(Windows) orwhich dot(macOS/Linux) - Install Graphviz with:
winget install graphviz(Windows) orbrew install graphviz(macOS) - Note: Not needed for ASCII output (default)
Empty visualization:
- Check that you're in a directory with Terraform files (*.tf)
- Ensure Terraform files are valid and can be parsed
Large file sizes:
- Complex infrastructures generate large PNGs
- Consider splitting large configurations into modules
Verbose Mode
Use -v flag to see detailed information:
- Executable paths being used
- Directory changes
- File operations
- Cleanup actions
Advanced Usage
Direct Graphviz Commands
You can also use the DOT file directly with Graphviz command-line tools:
# Generate different formats (run with --keep-dot first)
dot -Tsvg terraform_graph.dot -o graph.svg
dot -Tpng terraform_graph.dot -o graph.png
dot -Tpdf terraform_graph.dot -o graph.pdf
# Generate interactive HTML
dot -Tsvg terraform_graph.dot | dot -Tcmapx > graph.map
Use: uv run python terraform_viz.py --tf-dir "C:/../dev" to visualize dev environment
Integration
Documentation
Perfect for including infrastructure diagrams in:
- README files
- Wiki pages
- Architecture documents
- Presentations
CI/CD
Perfect for CI/CD pipelines - ASCII output works great in logs and doesn't require Graphviz:
# In your CI/CD pipeline - shows diagram in logs
terraform-viz --tf-dir ./infrastructure
# Generate PNG for artifacts
terraform-viz --tf-dir ./infrastructure -o infrastructure.png
Can be automated in pipelines to:
- Display infrastructure changes in build logs
- Generate PNG diagrams for deployment reports
- Archive infrastructure snapshots
- Validate Terraform configurations
Development
Building & Testing
# Build package
uv build
# Test CLI (shows ASCII by default)
uv run terraform-viz --help
# Test ASCII mode (default)
uv run terraform-viz --tf-dir /path/to/terraform
# Test PNG generation
uv run terraform-viz --tf-dir /path/to/terraform -o output.png
Project Structure
terraform-viz/
โโโ .github/workflows/ # CI/CD pipelines
โโโ examples/ # Sample DOT files
โโโ src/terraform_viz/ # Source code
โ โโโ cli.py # CLI entry point
โ โโโ config.py # Configuration
โ โโโ orchestrator.py # Main orchestration
โ โโโ renderer.py # PNG rendering
โ โโโ ascii_renderer.py # ASCII rendering
โ โโโ graph_generator.py # Terraform graph generation
โ โโโ file_manager.py # File operations
โ โโโ executables.py # Executable finding
โโโ output/ # Generated visualizations
โโโ pyproject.toml # Package configuration
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
Publishing to PyPI
For Maintainers
One-time setup:
- Configure PyPI Trusted Publishing at https://pypi.org/manage/account/publishing/
- Project:
terraform-viz - Owner:
pedropcamellon - Repository:
terraform-viz - Workflow:
publish.yml
- Project:
To release a new version:
# 1. Update version in pyproject.toml and CHANGELOG.md
# 2. Commit changes
git add pyproject.toml CHANGELOG.md
git commit -m "Release v0.2.0"
git push
# 3. Create and push tag
git tag v0.2.0
git push origin v0.2.0
# 4. Create GitHub release (triggers automatic PyPI publish)
gh release create v0.2.0 --title "v0.2.0" --notes-file CHANGELOG.md
The GitHub Action will automatically build and publish to PyPI.
License
MIT License - see LICENSE file for details.
Links
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 terraform_viz-0.3.0.tar.gz.
File metadata
- Download URL: terraform_viz-0.3.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
577d3c2a21305447e2fa7f915ad9fd8de559fda814c6546e47b55e311b15c629
|
|
| MD5 |
0749878d37c6384c00f49566a767e283
|
|
| BLAKE2b-256 |
a6dcedde42a009351046d7c223b80cadcb54f6ebc194a3c70f92abea4e7511a0
|
Provenance
The following attestation bundles were made for terraform_viz-0.3.0.tar.gz:
Publisher:
publish.yml on pedropcamellon/terraform-viz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terraform_viz-0.3.0.tar.gz -
Subject digest:
577d3c2a21305447e2fa7f915ad9fd8de559fda814c6546e47b55e311b15c629 - Sigstore transparency entry: 820473579
- Sigstore integration time:
-
Permalink:
pedropcamellon/terraform-viz@8733f8d0bb9592a0f2433633b15d8c421538a529 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/pedropcamellon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8733f8d0bb9592a0f2433633b15d8c421538a529 -
Trigger Event:
release
-
Statement type:
File details
Details for the file terraform_viz-0.3.0-py3-none-any.whl.
File metadata
- Download URL: terraform_viz-0.3.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfbbd70d1558fd147b854e403d1bfc56608d97704ca039604f8fdc0d1c2f2e86
|
|
| MD5 |
034107208dbd023642b2f2462ac50896
|
|
| BLAKE2b-256 |
733cf2ba1cdf932b15ba1aa059620638880c40731bc212ea22b353d1efceb725
|
Provenance
The following attestation bundles were made for terraform_viz-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on pedropcamellon/terraform-viz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
terraform_viz-0.3.0-py3-none-any.whl -
Subject digest:
bfbbd70d1558fd147b854e403d1bfc56608d97704ca039604f8fdc0d1c2f2e86 - Sigstore transparency entry: 820473590
- Sigstore integration time:
-
Permalink:
pedropcamellon/terraform-viz@8733f8d0bb9592a0f2433633b15d8c421538a529 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/pedropcamellon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8733f8d0bb9592a0f2433633b15d8c421538a529 -
Trigger Event:
release
-
Statement type: