Dynamic Infrastructure Documentation Generator (DIGen)
Executive Summary
DIGen is a modular, event-driven system that automatically generates and updates human-readable, interactive documentation for Infrastructure as Code (IaC) deployments. It parses IaC files (e.g., Terraform, Pulumi), builds dependency graphs, diffs planned vs. actual state in real-time, and renders outputs as Markdown, interactive dashboards, or wikis.
Key features:
- Dynamic Updates: Triggered by Git hooks, file watchers, or cloud webhooks.
- Visual Dependency Graphs: Interactive graphs showing resource relationships.
- Real-Time Diffing: Highlights drifts, changes, and compliance issues.
- Multi-IaC Support: Extensible for Terraform, CloudFormation, Ansible, etc.
- Output Formats: Markdown (GitHub Wiki), HTML dashboards (Grafana-like), PDF exports.
Target Users: DevOps teams, SREs, auditors needing always-up-to-date infra docs without manual toil.
High-Level Architecture
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Triggers │───▶│ IaC Parser │───▶│ Dependency Graph │
│ (Git webhook, │ │ + State Reader │ │ Builder │
│ file watcher) │ └──────────────────┘ └──────────────────┘
└─────────────────┘ │ │
▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Diff Engine │◀──▶│ Cache/DB │◀───▶│ Doc Generator │
│ (Plan vs. State)│ │ (Redis/Postgres) │ │ (MD/HTML/SVG) │
└─────────────────┘ └──────────────────┘ └──────────────────┘
│
▼
┌─────────────────┐ ┌──────────────────┐
│ API/UI Server │───▶│ Outputs │
│ (FastAPI + React)│ │ (Wiki, Dashboard│
└─────────────────┘ │ Slack/Teams) │
└──────────────────┘
- Event-Driven Pipeline: Uses Apache Kafka or NATS for decoupling.
- Scalable: Deployable on Kubernetes with Helm charts.
- Storage: Postgres for historical diffs/graphs; Redis for real-time cache.
Core Components
1. Triggers & Watchers
- File Watcher:
watchdog or inotify for local IaC changes.
- Git Integration: GitHub/GitLab webhooks trigger on push/merge to
main.
- Cloud Hooks: Terraform Cloud/Enterprise webhooks for apply events.
- Polling Fallback: Cron jobs for state refresh (e.g., every 5min).
- Implementation: Python
fastapi endpoint receiving payloads, dispatching to message queue.
2. IaC Parser
- Parsers:
| IaC Tool | Library | Outputs |
|---|
| Terraform | hcl2json + cdk-tf | Resources, vars, deps |
| Pulumi | pulumi convert | YAML/JSON stack |
| CloudFormation | cfn-flip + troposphere | Template AST |
| Ansible | ansible-lint + YAML parser | Playbooks as graph |
- Extensibility: Plugin system (e.g.,
stevedore in Python) for custom parsers.
- Extraction:
- Resources: Type, name, attributes (e.g.,
aws_instance.web).
- Dependencies: Explicit (
depends_on), implicit (references like ${aws_vpc.main.id}).
- Variables/Outputs: Resolved via
tf vars simulation.
3. State Reader
- Fetches real-time state:
| Backend | Method |
|---|
| Terraform | terraform show -json or TF Cloud API |
| Pulumi | Pulumi API/CLI |
| AWS | SSM/CloudFormation API |
- Handles remote backends (S3, Consul) with credential rotation via Vault.
4. Dependency Graph Builder
- Graph Representation: Directed Acyclic Graph (DAG) using
networkx (Python) or Neo4j.
- Nodes: Resources (label: type.name, props: attributes).
- Edges: Dependencies (explicit/implicit), data flows.
- Enrichment:
- Labels with costs, regions, tags.
- Cycles detection & warnings.
- Visualization:
5. Real-Time State Diffing
- Diff Engine (
difflib + custom IaC-aware matcher):
- Plan vs. State:
terraform plan -json → normalized schema → diff.
- Drift Detection: Compare parsed state vs. live cloud API queries (e.g., AWS DescribeInstances).
- Change Classification:
| Type | Example | Highlight |
|---|
| Add | New EC2 instance | Green |
| Modify | Instance type upgrade | Yellow |
| Delete | Removed S3 bucket | Red |
| Drift | Tags mismatch | Orange |
- Real-Time: WebSocket pushes diffs; historical trends in Postgres.
- Compliance Checks: Integrate Open Policy Agent (OPA) for rules like "No public S3 buckets".
6. Documentation Generator
- Templates: Jinja2 for Markdown/HTML.
- Outputs:
- GitHub Wiki sync via API.
- Confluence/Jira integration.
- Slack/Teams notifications with embeds.
- PDF via WeasyPrint.
7. API & UI
- Backend: FastAPI with Pydantic models for resources/graphs.
- Endpoints:
/docs/{project}, /graph/{project}.svg, /diff/{project} (WebSocket).
- Frontend: React + Vite + Cytoscape for interactive graphs/diffs.
- Auth: OIDC (Keycloak) + RBAC (view/edit per project).
Deployment & Ops
- Dockerized Services: Parser (Python), API (FastAPI), UI (Node), Queue (Kafka).
- Helm Chart: For K8s, with Postgres/Redis operators.
- Monitoring: Prometheus + Grafana; alert on parse failures.
- CI/CD: GitHub Actions to build/test parsers.
- Scalability: Horizontal pod autoscaling; graph gen offloaded to workers.
Implementation Roadmap
- MVP (2 weeks): Terraform-only parser + basic MD gen + local watcher.
- Phase 1 (4 weeks): Graphs (NetworkX + DOT), state diffing, FastAPI.
- Phase 2 (4 weeks): UI dashboard, multi-IaC, webhooks.
- Phase 3 (4 weeks): Cloud integrations, compliance, exports.
Potential Challenges & Mitigations
- Schema Drift: Normalize all IaC to common JSON schema (e.g., OpenTofu schema).
- Performance: Cache parsed state (TTL 1min); async graph rendering.
- Secrets Handling: Strip sensitive attrs during parsing (use
tfmask).
- Cost: Free tier tools; ~$50/mo for Postgres/Redis on small scale.
This design provides a "living documentation" system, reducing docs debt by 90%+. Source code skeleton available on request—let's iterate! 🕵️♂️