terraformgraph 1.0.3__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/LICENSE +1 -1
  2. terraformgraph-1.0.4/PKG-INFO +386 -0
  3. terraformgraph-1.0.4/README.md +348 -0
  4. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/pyproject.toml +1 -1
  5. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph/__main__.py +1 -1
  6. terraformgraph-1.0.4/terraformgraph/aggregator.py +1037 -0
  7. terraformgraph-1.0.4/terraformgraph/config/aggregation_rules.yaml +407 -0
  8. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph/config_loader.py +9 -8
  9. terraformgraph-1.0.4/terraformgraph/icons.py +778 -0
  10. terraformgraph-1.0.4/terraformgraph/layout.py +703 -0
  11. terraformgraph-1.0.4/terraformgraph/main.py +403 -0
  12. terraformgraph-1.0.4/terraformgraph/parser.py +583 -0
  13. terraformgraph-1.0.4/terraformgraph/renderer.py +2851 -0
  14. terraformgraph-1.0.4/terraformgraph/terraform_tools.py +355 -0
  15. terraformgraph-1.0.4/terraformgraph/variable_resolver.py +180 -0
  16. terraformgraph-1.0.4/terraformgraph.egg-info/PKG-INFO +386 -0
  17. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph.egg-info/SOURCES.txt +8 -1
  18. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/tests/test_config_loader.py +4 -2
  19. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/tests/test_integration.py +3 -4
  20. terraformgraph-1.0.4/tests/test_layout.py +478 -0
  21. terraformgraph-1.0.4/tests/test_parser.py +385 -0
  22. terraformgraph-1.0.4/tests/test_terraform_tools.py +307 -0
  23. terraformgraph-1.0.4/tests/test_variable_resolver.py +307 -0
  24. terraformgraph-1.0.4/tests/test_vpc_structure.py +751 -0
  25. terraformgraph-1.0.3/PKG-INFO +0 -163
  26. terraformgraph-1.0.3/README.md +0 -125
  27. terraformgraph-1.0.3/terraformgraph/aggregator.py +0 -140
  28. terraformgraph-1.0.3/terraformgraph/config/aggregation_rules.yaml +0 -132
  29. terraformgraph-1.0.3/terraformgraph/icons.py +0 -795
  30. terraformgraph-1.0.3/terraformgraph/layout.py +0 -239
  31. terraformgraph-1.0.3/terraformgraph/main.py +0 -200
  32. terraformgraph-1.0.3/terraformgraph/parser.py +0 -344
  33. terraformgraph-1.0.3/terraformgraph/renderer.py +0 -1154
  34. terraformgraph-1.0.3/terraformgraph.egg-info/PKG-INFO +0 -163
  35. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/setup.cfg +0 -0
  36. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph/__init__.py +0 -0
  37. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph/config/logical_connections.yaml +0 -0
  38. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph.egg-info/dependency_links.txt +0 -0
  39. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph.egg-info/entry_points.txt +0 -0
  40. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph.egg-info/requires.txt +0 -0
  41. {terraformgraph-1.0.3 → terraformgraph-1.0.4}/terraformgraph.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 [Your Name]
3
+ Copyright (c) 2024 Ferdinando Bonsegna
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: terraformgraph
3
+ Version: 1.0.4
4
+ Summary: Generate interactive architecture diagrams from Terraform configurations
5
+ Author-email: Ferdinando Bonsegna <1bonsegnaferdinando@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ferdinandobons/terraformgraph
8
+ Project-URL: Documentation, https://github.com/ferdinandobons/terraformgraph#readme
9
+ Project-URL: Repository, https://github.com/ferdinandobons/terraformgraph.git
10
+ Project-URL: Issues, https://github.com/ferdinandobons/terraformgraph/issues
11
+ Keywords: terraform,infrastructure,diagram,aws,visualization,architecture,terraformgraph
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Software Development :: Documentation
24
+ Classifier: Topic :: System :: Systems Administration
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: python-hcl2>=4.3.0
29
+ Requires-Dist: PyYAML>=6.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
33
+ Requires-Dist: black>=23.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
35
+ Requires-Dist: mypy>=1.0; extra == "dev"
36
+ Requires-Dist: types-PyYAML>=6.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # terraformgraph
40
+
41
+ Generate interactive architecture diagrams from your Terraform configurations. Supports AWS resources with automatic service grouping, relationship detection, and beautiful SVG/HTML output.
42
+
43
+ ![Example Diagram](docs/diagram.jpg)
44
+
45
+ ## Features
46
+
47
+ - **Automatic parsing** of Terraform HCL files with state integration
48
+ - **Smart resource grouping** into logical services (ECS, RDS, S3, etc.)
49
+ - **Relationship detection** based on resource references
50
+ - **VPC structure visualization** with subnets and availability zones
51
+ - **VPC endpoint visualization** with service-specific icons (S3, DynamoDB, ECR, etc.)
52
+ - **Accurate resource positioning** using Terraform state
53
+ - **Interactive HTML output** with:
54
+ - Drag-and-drop repositioning of service icons
55
+ - Click-to-highlight connections between services
56
+ - Click-to-highlight source and target endpoints
57
+ - Save/Load layout persistence
58
+ - Zoom and pan navigation
59
+ - **PNG/JPG export** directly from the browser
60
+ - **Customizable** via YAML configuration files
61
+ - **No cloud credentials required** - works entirely offline
62
+
63
+ ## Prerequisites
64
+
65
+ ### Required
66
+
67
+ - **Python 3.9+** (3.9, 3.10, 3.11, or 3.12)
68
+ - **pip** (Python package manager)
69
+ - **Terraform CLI** - Required for generating state JSON
70
+
71
+ ### Optional
72
+
73
+ - **AWS Architecture Icons** - For beautiful service icons (see [With AWS Icons](#with-aws-icons))
74
+
75
+ ### Terraform Setup
76
+
77
+ Before using terraformgraph, initialize and apply your Terraform configuration:
78
+
79
+ ```bash
80
+ cd ./infrastructure
81
+ terraform init
82
+ terraform apply # or terraform plan for undeployed infrastructure
83
+ ```
84
+
85
+ This creates the state data that terraformgraph uses for accurate diagram generation.
86
+
87
+ ## Installation
88
+
89
+ ### From PyPI
90
+
91
+ ```bash
92
+ pip install terraformgraph
93
+ ```
94
+
95
+ ### From Source
96
+
97
+ ```bash
98
+ git clone https://github.com/ferdinandobons/terraformgraph.git
99
+ cd terraformgraph
100
+ pip install -e .
101
+ ```
102
+
103
+ ### Development Installation
104
+
105
+ For contributing or running tests:
106
+
107
+ ```bash
108
+ git clone https://github.com/ferdinandobons/terraformgraph.git
109
+ cd terraformgraph
110
+ pip install -e ".[dev]"
111
+ ```
112
+
113
+ This installs additional development dependencies:
114
+ - `pytest` - Testing framework
115
+ - `pytest-cov` - Code coverage
116
+ - `black` - Code formatting
117
+ - `ruff` - Linting
118
+ - `mypy` - Type checking
119
+
120
+ ## Quick Start
121
+
122
+ ### Basic Usage
123
+
124
+ Generate a diagram from a Terraform directory:
125
+
126
+ ```bash
127
+ terraformgraph -t ./infrastructure
128
+ ```
129
+
130
+ This creates `terraformgraph.html` in the current directory.
131
+
132
+ **Note:** The tool automatically generates state JSON from `terraform show -json` if no cached state exists. Make sure your Terraform is initialized (`terraform init`) before running.
133
+
134
+ ### With Environment Subdirectories
135
+
136
+ If your Terraform is organized by environment:
137
+
138
+ ```bash
139
+ terraformgraph -t ./infrastructure -e prod -o prod-diagram.html
140
+ ```
141
+
142
+ ### With Pre-generated State File
143
+
144
+ If you want to generate the state file manually (useful for CI/CD):
145
+
146
+ ```bash
147
+ # Generate state JSON
148
+ cd ./infrastructure
149
+ terraform show -json > state.json
150
+
151
+ # Use it with terraformgraph
152
+ terraformgraph -t ./infrastructure --state-file state.json
153
+ ```
154
+
155
+ ### Force State Refresh
156
+
157
+ To regenerate the cached state file:
158
+
159
+ ```bash
160
+ terraformgraph -t ./infrastructure --refresh-state
161
+ ```
162
+
163
+ ### With AWS Icons
164
+
165
+ For beautiful AWS service icons, download the [AWS Architecture Icons](https://aws.amazon.com/architecture/icons/) and extract them:
166
+
167
+ ```bash
168
+ terraformgraph -t ./infrastructure -i ./AWS_Icons
169
+ ```
170
+
171
+ The tool also auto-discovers icons in these locations:
172
+ - `./aws-official-icons`
173
+ - `~/aws-official-icons`
174
+ - `~/.terraformgraph/icons`
175
+
176
+ ## Command Line Options
177
+
178
+ | Option | Short | Required | Description |
179
+ |--------|-------|----------|-------------|
180
+ | `--terraform` | `-t` | Yes | Path to Terraform directory |
181
+ | `--environment` | `-e` | No | Environment subdirectory (dev, staging, prod) |
182
+ | `--icons` | `-i` | No | Path to AWS icons directory |
183
+ | `--output` | `-o` | No | Output HTML file path (default: `terraformgraph.html`) |
184
+ | `--verbose` | `-v` | No | Enable debug output |
185
+ | `--state-file` | `-s` | No | Path to pre-generated state JSON file |
186
+ | `--refresh-state` | | No | Force regeneration of cached state file |
187
+
188
+ ### Examples
189
+
190
+ ```bash
191
+ # Basic usage (auto-generates state)
192
+ terraformgraph -t ./infrastructure
193
+
194
+ # With environment
195
+ terraformgraph -t ./infrastructure -e prod
196
+
197
+ # With custom output
198
+ terraformgraph -t ./infrastructure -o my-diagram.html
199
+
200
+ # With AWS icons
201
+ terraformgraph -t ./infrastructure -i ~/Downloads/AWS_Icons
202
+
203
+ # With pre-generated state file
204
+ terraformgraph -t ./infrastructure -s state.json
205
+
206
+ # Force state refresh
207
+ terraformgraph -t ./infrastructure --refresh-state
208
+
209
+ # Full options with verbose output
210
+ terraformgraph -t ./infrastructure -e prod -i ./icons -o prod.html -v
211
+ ```
212
+
213
+ ## How It Works
214
+
215
+ 1. **State Acquisition**: terraformgraph reads Terraform state (from cached file, provided file, or auto-generated via `terraform show -json`)
216
+ 2. **HCL Parsing**: Parses `.tf` files to understand resource structure and relationships
217
+ 3. **Resource Aggregation**: Groups resources into logical services (e.g., all ECS-related resources into an "ECS" service)
218
+ 4. **VPC Structure**: Builds VPC topology with availability zones, subnets, and endpoints
219
+ 5. **Layout Computation**: Calculates optimal positions for services in the diagram
220
+ 6. **HTML Generation**: Creates interactive SVG diagram with pan, zoom, and drag capabilities
221
+
222
+ ## Configuration
223
+
224
+ ### Custom Aggregation Rules
225
+
226
+ Create `~/.terraformgraph/aggregation_rules.yaml` to customize how resources are grouped:
227
+
228
+ ```yaml
229
+ compute:
230
+ my_custom_service:
231
+ primary: ["aws_my_resource"]
232
+ secondary: ["aws_my_helper"]
233
+ in_vpc: true
234
+ ```
235
+
236
+ ### Custom Connections
237
+
238
+ Create `~/.terraformgraph/logical_connections.yaml` to define service relationships:
239
+
240
+ ```yaml
241
+ connections:
242
+ - source: my_service
243
+ target: another_service
244
+ label: "Custom Connection"
245
+ type: data_flow
246
+ ```
247
+
248
+ ## Supported Resources
249
+
250
+ The tool supports 100+ AWS resource types including:
251
+
252
+ ### Compute
253
+ - ECS (Clusters, Services, Task Definitions)
254
+ - EC2 (Instances, Auto Scaling Groups, Launch Templates)
255
+ - Lambda (Functions, Layers, Event Source Mappings)
256
+ - EKS (Clusters, Node Groups)
257
+ - Batch (Compute Environments, Job Queues)
258
+
259
+ ### Networking
260
+ - VPC (VPCs, Subnets, Route Tables, Internet Gateways)
261
+ - VPC Endpoints (Gateway and Interface types)
262
+ - Load Balancers (ALB, NLB, Target Groups)
263
+ - Route53 (Zones, Records)
264
+ - CloudFront (Distributions)
265
+ - API Gateway (REST and HTTP APIs)
266
+
267
+ ### Storage
268
+ - S3 (Buckets, Bucket Policies)
269
+ - EBS (Volumes, Snapshots)
270
+ - EFS (File Systems, Mount Targets)
271
+
272
+ ### Database
273
+ - RDS (Instances, Clusters, Parameter Groups)
274
+ - DynamoDB (Tables, Global Tables)
275
+ - ElastiCache (Clusters, Replication Groups)
276
+ - DocumentDB, Neptune, Redshift
277
+
278
+ ### Messaging & Integration
279
+ - SQS (Queues)
280
+ - SNS (Topics, Subscriptions)
281
+ - EventBridge (Rules, Event Buses)
282
+ - Step Functions (State Machines)
283
+ - Kinesis (Streams, Firehose)
284
+
285
+ ### Security
286
+ - IAM (Roles, Policies, Users, Groups)
287
+ - KMS (Keys, Aliases)
288
+ - Secrets Manager (Secrets)
289
+ - WAF (Web ACLs, Rules)
290
+ - Security Groups
291
+
292
+ ### Monitoring & Management
293
+ - CloudWatch (Alarms, Log Groups, Dashboards)
294
+ - CloudTrail
295
+ - Config Rules
296
+
297
+ ### And many more...
298
+
299
+ See the full list in the [aggregation_rules.yaml](terraformgraph/config/aggregation_rules.yaml) configuration file.
300
+
301
+ ## Output
302
+
303
+ The generated HTML file includes:
304
+
305
+ ### Interactive Features
306
+ - **Pan and Zoom** - Navigate large diagrams easily
307
+ - **Drag-and-drop** - Reposition service icons within their containers
308
+ - **Click connections** - Click any connection line to highlight the data flow
309
+ - **Click services** - Click any service to see all its connections highlighted
310
+ - **Save layout** - Persist your custom icon positions to browser storage
311
+ - **Load layout** - Restore previously saved positions
312
+
313
+ ### Export Options
314
+ - **PNG Export** - High-quality raster image
315
+ - **JPG Export** - Compressed raster image
316
+
317
+ ### Visual Elements
318
+ - **VPC containers** with subnet boundaries
319
+ - **Availability zone indicators**
320
+ - **Service icons** (with AWS icons or colored fallbacks)
321
+ - **Connection lines** showing relationships
322
+ - **Resource counts** for grouped resources
323
+ - **Legend** with interaction instructions
324
+
325
+ ## Project Structure
326
+
327
+ ```
328
+ terraformgraph/
329
+ ├── terraformgraph/
330
+ │ ├── __init__.py # Package init with version
331
+ │ ├── __main__.py # Entry point for python -m
332
+ │ ├── main.py # CLI entry point
333
+ │ ├── parser.py # Terraform HCL parser
334
+ │ ├── aggregator.py # Resource grouping logic
335
+ │ ├── layout.py # Diagram layout engine
336
+ │ ├── renderer.py # SVG/HTML renderer
337
+ │ ├── icons.py # AWS icon mapper
338
+ │ ├── terraform_tools.py # Terraform CLI integration
339
+ │ ├── variable_resolver.py # Variable resolution
340
+ │ └── config/ # Default configuration files
341
+ ├── tests/ # Test suite
342
+ ├── example/ # Example Terraform configs
343
+ └── docs/ # Documentation
344
+ ```
345
+
346
+ ## Running Tests
347
+
348
+ ```bash
349
+ # Run all tests
350
+ pytest
351
+
352
+ # Run with coverage
353
+ pytest --cov=terraformgraph
354
+
355
+ # Run specific test file
356
+ pytest tests/test_parser.py
357
+
358
+ # Run with verbose output
359
+ pytest -v
360
+ ```
361
+
362
+ ## Contributing
363
+
364
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
365
+
366
+ ### Development Workflow
367
+
368
+ 1. Fork the repository
369
+ 2. Create a feature branch
370
+ 3. Make your changes
371
+ 4. Run tests: `pytest`
372
+ 5. Format code: `black terraformgraph/`
373
+ 6. Lint code: `ruff check terraformgraph/`
374
+ 7. Submit a pull request
375
+
376
+ ## Changelog
377
+
378
+ See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
379
+
380
+ ## License
381
+
382
+ MIT License - see [LICENSE](LICENSE) for details.
383
+
384
+ ## Author
385
+
386
+ Ferdinando Bonsegna - [GitHub](https://github.com/ferdinandobons)