Terraform Plan Visualizer: Generate Beautiful HTML Reports with AI Analysis
A Complete Guide to Visualizing Terraform Changes Like a Pro
Terraform plans are incredibly powerful, but they can quickly become overwhelming. When you are managing complex infrastructure across AWS, Azure, or GCP, reading raw command-line stdout or digging through hundreds of lines of nested JSON isn't practical—especially during peer architecture reviews or security compliance audits.
In this guide, I'll show you how to transform raw Terraform plans into beautiful, professional HTML dashboards featuring optional AI-powered explanations using local LLMs (completely private and free).
What you'll build: Interactive HTML dashboards of your changes, AI-generated plain-English explanations of impacts, color-coded resource states (Create/Update/Delete), and a fully responsive layout ready to share with your team.
Why This Matters
Before: CLI Chaos 🔴
$ terraform plan
# Good luck explaining this to your manager!
After: Visual Clarity 🟢
✔ One portable, lightweight HTML file
✔ Visual summary of exactly what's modifying
✔ AI analysis highlighting critical risks & impacts
✔ Zero "what does this code block do?" questions
Prerequisites
To run the visualizer, make sure you have Terraform and Python installed, along with Ollama if you'd like to use the local AI features:
terraform --version
python3 --version
# Optional but recommended: Ollama for local AI
curl -fsSL https://ollama.com/install.sh | sh
ollama pull llama3.1
The Script
Below is the script configuration placeholder. Save this as clone this terraform_viz.py on your local machine and run it to compile your Terraform details into the clean visual layout shown above.
clone this https://gitlab.com/praveen.balla41/ami-ml-playground/-/blob/main/tf_diff_analyzer.py?ref_type=heads python3 terraform_viz.py --path ./terraform_dir --output plan_report.html
Usage & Examples
You can execute the script with various options to fit your workflow needs:
python3 terraform_viz.py --path ./terraform
# Generate with AI risk analysis (requires Ollama running)
python3 terraform_viz.py --path ./terraform --llm-model llama3.1
# Fast mode (no AI processing)
python3 terraform_viz.py --path ./terraform --no-llm
Performance Quick-Reference
Depending on the footprint of your architecture deployments, use this operational index to optimize execution speeds:
| Plan Complexity | Recommended Flag | Expected Processing Time |
|---|---|---|
| < 50 resources | --llm-model llama3.1 |
~15 seconds |
| 50 - 200 resources | --no-llm |
~5 seconds |
| > 200 resources | --no-llm |
~10 seconds |
Advanced CI/CD Pipeline Integration
You can seamlessly hook this visualizer straight into your automated deployment pipelines. Here is an example step configuration for GitHub Actions:
- name: Generate Visual Report
run: |
terraform plan -out=plan.tfplan
python3 terraform_viz.py --path . --output report.html
- name: Publish Artifact
uses: actions/upload-artifact@v3
with:
name: tf-report
path: report.html
Conclusion
You now possess a completely free, private, and localized visual reporting workflow for your IaC modifications. Running this step before applying changes reduces manual review errors, makes code approvals straightforward, and gives your engineering teams clear insight into your changes.
Comments
Post a Comment