TerraLens 0.1.0__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.
@@ -0,0 +1,471 @@
1
+ Metadata-Version: 2.4
2
+ Name: TerraLens
3
+ Version: 0.1.0
4
+ Summary: Terraform TUI viewer
5
+ Author: Bubu
6
+ Project-URL: Homepage, https://github.com/bhuvan-raj/TerraLens
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+
10
+ # Insight-TF
11
+
12
+ > A terminal-based Terraform dashboard built with [Textual](https://textual.textualize.io/) — manage your infrastructure without leaving the command line.
13
+
14
+ ![Python](https://img.shields.io/badge/Python-3.10%2B-blue?logo=python&logoColor=white)
15
+ ![Textual](https://img.shields.io/badge/Textual-0.47%2B-purple)
16
+ ![Terraform](https://img.shields.io/badge/Terraform-1.0%2B-7B42BC?logo=terraform&logoColor=white)
17
+ ![License](https://img.shields.io/badge/License-MIT-green)
18
+ ![Platform](https://img.shields.io/badge/Platform-Linux%20%7C%20macOS%20%7C%20Windows-lightgrey)
19
+
20
+ ---
21
+
22
+ ## What is Insight-TF?
23
+
24
+ Insight-TF turns your Terraform workflow into a fully interactive TUI — browse state, inspect resources, plan, apply, detect drift, estimate costs, and scaffold new resources, all from a single terminal window.
25
+
26
+
27
+ https://github.com/user-attachments/assets/2e3fa276-8a02-405f-b893-262f8dbf1dd8
28
+
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ Choose the method that suits you best.
35
+
36
+ ### Option 1 — Download a Binary (No Python required)
37
+
38
+ Pre-built binaries are available for **Ubuntu (Linux)** and **Windows** on the [Releases page](https://github.com/bhuvan-raj/Insight-Q/releases).
39
+
40
+ **Ubuntu / Linux:**
41
+ ```bash
42
+ # Download the latest binary
43
+ curl -L https://github.com/bhuvan-raj/Insight-Q/releases/latest/download/insight-tf-linux -o insight-tf
44
+
45
+ # Make it executable
46
+ chmod +x insight-tf
47
+
48
+ # Run it from your Terraform project directory
49
+ cd ~/my-terraform-project
50
+ ./insight-tf
51
+ ```
52
+
53
+ **Windows:**
54
+ ```powershell
55
+ # Download insight-tf-windows.exe from the Releases page, then run:
56
+ .\insight-tf-windows.exe
57
+ ```
58
+
59
+ > No Python, no pip, no dependencies — everything is bundled inside the binary.
60
+
61
+ ---
62
+
63
+ ### Option 2 — Install via pip (Python users)
64
+
65
+ Insight-TF is published on [PyPI](https://pypi.org/project/insight-tf/):
66
+
67
+ ```bash
68
+ pip install insight-tf
69
+ ```
70
+
71
+ Then run it from your Terraform project directory:
72
+
73
+ ```bash
74
+ cd ~/my-terraform-project
75
+ insight-tf
76
+
77
+ # Or pass the state file path explicitly
78
+ insight-tf /path/to/terraform.tfstate
79
+ ```
80
+
81
+ ---
82
+
83
+ ### Option 3 — Install from Source
84
+
85
+ ```bash
86
+ # 1. Clone the repository
87
+ git clone https://github.com/bhuvan-raj/Insight-Q.git
88
+ cd Insight-Q
89
+
90
+ # 2. Create a virtual environment
91
+ python3 -m venv .venv
92
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
93
+
94
+ # 3. Install dependencies
95
+ pip install -r requirements.txt
96
+ ```
97
+
98
+ ---
99
+
100
+ ### ⚠️ Required: Run the Setup Script
101
+
102
+ Regardless of which installation method you use, **you must run `setup.py` once** before launching the app for the first time:
103
+
104
+ ```bash
105
+ python setup.py
106
+ ```
107
+
108
+ The setup script automatically:
109
+ - Checks Python 3.10+
110
+ - Installs `textual` and `rich`
111
+ - Checks for Terraform in `PATH`
112
+ - Downloads and installs **Infracost** for your platform (Linux / macOS / Windows)
113
+ - Guides you through Infracost authentication (free — no credit card required)
114
+ - Writes `.insight-tf.json` with resolved binary paths
115
+
116
+ > **Why is this needed?** Infracost (used for cost estimation) requires authentication and its binary path needs to be recorded so Insight-TF can find it at runtime.
117
+
118
+ ---
119
+
120
+ ## Features
121
+
122
+ | Feature | Description |
123
+ |---|---|
124
+ | **📊 Overview** | Terraform version, state serial, total resources, provider count, full resource table |
125
+ | **🌲 Resource Tree** | Resources grouped by type — click any leaf to inspect all attributes |
126
+ | **🔍 Plan** | Streams real `terraform plan` output line-by-line |
127
+ | **⚡ Apply Now** | Runs `terraform apply -auto-approve` and reloads state on success |
128
+ | **💰 Cost Estimate** | Real Infracost pricing breakdown by resource with monthly totals |
129
+ | **🔄 Drift Detection** | `terraform plan -refresh-only -detailed-exitcode` with parsed summary |
130
+ | **➕ Add Resource** | 3-step wizard: provider → 334 AWS resources across 20 categories → HCL preview |
131
+ | **🗑️ Destroy** | Targeted destroy with confirmation modal before execution |
132
+ | **🔁 State Reload** | Press `r` to reload state from disk at any time |
133
+
134
+ ---
135
+
136
+ ## Requirements
137
+
138
+ | Requirement | Version | Notes |
139
+ |---|---|---|
140
+ | Python | 3.10+ | Required for modern typing syntax |
141
+ | Terraform | 1.0+ | Must be in `PATH` for Plan / Apply / Destroy / Drift |
142
+ | Infracost | any | Auto-installed by `setup.py` for Cost Estimate |
143
+ | OS | Linux / macOS / Windows | Tested on Ubuntu 22.04+, macOS 13+ |
144
+
145
+ ---
146
+
147
+ ## Quick Start
148
+
149
+ ### 1. Clone the repository
150
+
151
+ ```bash
152
+ git clone https://github.com/bhuvan-raj/Insight-Q.git
153
+ cd Insight-Q
154
+ ```
155
+
156
+ ### 2. Create a virtual environment
157
+
158
+ ```bash
159
+ python3 -m venv .venv
160
+ source .venv/bin/activate # Windows: .venv\Scripts\activate
161
+ ```
162
+
163
+ ### 3. Run the setup script
164
+
165
+ ```bash
166
+ python setup.py
167
+ ```
168
+
169
+ ### 4. Launch the app
170
+
171
+ ```bash
172
+ # From your Terraform project directory (auto-loads terraform.tfstate)
173
+ cd ~/my-terraform-project
174
+ python /path/to/insight-tf/insight_tf.py
175
+
176
+ # Or pass the state file path explicitly
177
+ python insight_tf.py /path/to/terraform.tfstate
178
+ ```
179
+
180
+ > **No state file?** The app loads built-in sample AWS data so you can explore the UI immediately.
181
+
182
+ ---
183
+
184
+ ## Installation Details
185
+
186
+ ### Manual dependency install
187
+
188
+ ```bash
189
+ pip install textual>=0.47.0 rich>=13.0.0
190
+ ```
191
+
192
+ ### Infracost manual install
193
+
194
+ ```bash
195
+ # macOS
196
+ brew install infracost
197
+
198
+ # Linux
199
+ curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
200
+
201
+ # Authenticate (free — no credit card required)
202
+ infracost auth login
203
+ ```
204
+
205
+ ### Using a remote state backend
206
+
207
+ ```bash
208
+ # Terraform Cloud / any backend
209
+ terraform state pull > terraform.tfstate
210
+ python insight_tf.py
211
+
212
+ # AWS S3 backend
213
+ aws s3 cp s3://your-bucket/env/prod/terraform.tfstate ./terraform.tfstate
214
+ python insight_tf.py
215
+ ```
216
+
217
+ ---
218
+
219
+ ## Usage Guide
220
+
221
+ ### Keyboard Shortcuts
222
+
223
+ | Key | Action |
224
+ |---|---|
225
+ | `1` | Switch to Overview tab |
226
+ | `2` | Switch to Manage tab |
227
+ | `r` | Reload state from disk |
228
+ | `q` | Quit |
229
+ | `Esc` | Close any open modal or wizard |
230
+
231
+ ### Overview Tab
232
+
233
+ Displays a high-level snapshot of your infrastructure:
234
+
235
+ - **Terraform version** — read directly from the state file
236
+ - **State serial** — increments on every apply; useful for auditing
237
+ - **Total resources** — count of all managed resources
238
+ - **Provider count** — number of unique providers in use
239
+ - **Resource table** — type, name, provider, and instance count for every resource
240
+
241
+ ### Manage Tab
242
+
243
+ #### Resource Tree
244
+
245
+ The left panel shows all managed resources grouped by type. Click any resource leaf to load its full attribute map in the right panel, including nested maps and lists rendered as structured text.
246
+
247
+ #### Action Buttons
248
+
249
+ **➕ Add Resource**
250
+ Opens a 3-step wizard:
251
+ 1. **Select provider** — AWS supported; Azure, GCP, Oracle, Docker, Kubernetes coming soon
252
+ 2. **Browse resources** — 334 AWS resources across 20 categories with live search and category sidebar
253
+ 3. **Configure & preview** — fill in fields, review the generated HCL, then choose:
254
+ - **💾 Write File** — saves the `.tf` file and runs `terraform plan` to validate
255
+ - **🚀 Write & Apply** — saves the file, plans, then immediately applies
256
+
257
+ **🔍 Plan**
258
+ Streams the full output of `terraform plan -no-color` into the output panel in real time.
259
+
260
+ **💰 Cost Estimate**
261
+ Runs `infracost breakdown --path . --format json` and renders a formatted cost table:
262
+
263
+ ```
264
+ Resource Monthly
265
+ ────────────────────────────────────────────────────────────
266
+ aws_db_instance.main (db.t3.medium) $ 63.22
267
+ aws_instance.web (t3.micro) $ 8.47
268
+ aws_s3_bucket.assets usage-based
269
+ ────────────────────────────────────────────────────────────
270
+ TOTAL MONTHLY ESTIMATE $ 71.69
271
+ ```
272
+
273
+ **🔄 Detect Drift**
274
+ Runs `terraform plan -refresh-only -detailed-exitcode` and reports:
275
+ - ✅ **No drift** — infrastructure matches state exactly
276
+ - ⚠️ **Drift found** — lists each drifted resource with its status (changed / deleted outside Terraform / created outside Terraform)
277
+ - ❌ **Error** — shows full stderr output for debugging
278
+
279
+ **🗑️ Destroy Selected**
280
+ Select a resource leaf in the tree, click Destroy. A confirmation modal displays the full resource address (`type.name`) before executing `terraform destroy -target=<addr> -auto-approve`.
281
+
282
+ **⚡ Apply Now**
283
+ Runs `terraform apply -auto-approve -no-color` from the project directory. Streams all output in real time and automatically reloads the resource tree on success.
284
+
285
+ ---
286
+
287
+ ## AWS Resource Catalog
288
+
289
+ The Add Resource wizard includes **334 AWS resources** across **20 categories**:
290
+
291
+ | Category | Highlights |
292
+ |---|---|
293
+ | Compute | EC2, Auto Scaling, AMIs, EBS, EIP, placement groups, key pairs |
294
+ | Containers | ECS clusters/services/tasks, ECR repositories, EKS clusters/node groups/Fargate |
295
+ | Serverless | Lambda functions, aliases, layers, function URLs, event source mappings |
296
+ | Storage | S3 (all 13 sub-resources), EFS, FSx (Lustre/Windows/ONTAP), Glacier |
297
+ | Database | RDS, Aurora, DynamoDB, ElastiCache, Redshift, Neptune, DocumentDB, MemoryDB, OpenSearch |
298
+ | Networking | VPC, subnets, NAT/Internet gateways, Transit Gateway, Direct Connect, flow logs |
299
+ | Load Balancing | ALB, NLB, Classic ELB, target groups, listeners, routing rules |
300
+ | DNS & CDN | Route 53 (zones/records/health checks/resolver), CloudFront, Global Accelerator |
301
+ | IAM & Security | IAM users/groups/roles/policies, KMS, Secrets Manager, SSM, ACM, WAFv2, GuardDuty, Cognito |
302
+ | Messaging & Queuing | SQS, SNS, Amazon MQ, Kinesis, MSK Kafka, EventBridge, Pipes |
303
+ | Monitoring & Logging | CloudWatch (alarms/dashboards/logs/metrics), X-Ray, CloudTrail, AWS Config |
304
+ | API & Integration | API Gateway v1/v2, AppSync GraphQL, Step Functions |
305
+ | DevOps & CI/CD | CodeBuild, CodeCommit, CodeDeploy, CodePipeline, CodeArtifact, CloudFormation |
306
+ | Machine Learning | SageMaker, Bedrock, Rekognition, Lex v2, Comprehend |
307
+ | Data & Analytics | Glue, Athena, EMR, Lake Formation, QuickSight |
308
+ | IoT | IoT Core (things/certificates/rules), IoT Events, IoT Analytics |
309
+ | Application Services | Elastic Beanstalk, Lightsail, Amplify, App Runner, Batch |
310
+ | Cost & Billing | Budgets, Cost Explorer categories, Cost & Usage Reports |
311
+ | Migration | DMS replication, DataSync, Migration Hub |
312
+ | Management | Organizations, RAM sharing, Resource Groups, SSM maintenance, Service Quotas |
313
+
314
+ Resources with full guided forms (labelled fields, defaults, placeholders):
315
+
316
+ `aws_s3_bucket` · `aws_instance` · `aws_vpc` · `aws_subnet` · `aws_security_group` · `aws_db_instance` · `aws_iam_role` · `aws_lambda_function`
317
+
318
+ All other resources generate a scaffold HCL block with a direct link to the Terraform registry documentation for that resource type.
319
+
320
+ ---
321
+
322
+ ## Project Structure
323
+
324
+ ```
325
+ insight-tf/
326
+ ├── insight_tf.py # Main application (single file)
327
+ ├── setup.py # Auto-installer for all dependencies
328
+ ├── requirements.txt # Python dependencies
329
+ ├── .insight-tf.json # Generated by setup.py — binary paths config
330
+ └── README.md
331
+ ```
332
+
333
+ ### Architecture overview
334
+
335
+ | Class | Role |
336
+ |---|---|
337
+ | `InsightTF` | Root `App` — owns state, `_tf_dir`, tab switching, state reload |
338
+ | `OverviewPage` | Stat cards + resource summary table |
339
+ | `ManagePage` | Button bar, tree, attribute panel, output log, all action handlers |
340
+ | `ResourceTree` | Textual `Tree` subclass — left panel of Manage |
341
+ | `AttributePanel` | Scrollable right panel — renders full resource attributes |
342
+ | `ProviderSelectScreen` | Modal step 1 — choose cloud provider |
343
+ | `AWSResourcePickerScreen` | Modal step 2 — searchable catalog with category sidebar |
344
+ | `AddResourceWizard` | Modal step 3 — configure fields, preview HCL, write or apply |
345
+ | `ConfirmDestroyScreen` | Modal — confirmation gate before targeted destroy |
346
+
347
+ ---
348
+
349
+ ## Configuration
350
+
351
+ `.insight-tf.json` is written by `setup.py` and read at startup to locate binaries:
352
+
353
+ ```json
354
+ {
355
+ "infracost_path": "/usr/local/bin/infracost",
356
+ "terraform_path": "/usr/local/bin/terraform",
357
+ "setup_complete": true
358
+ }
359
+ ```
360
+
361
+ Edit this file manually if your binaries are in non-standard locations.
362
+
363
+ ---
364
+
365
+ ## Extending Insight-TF
366
+
367
+ ### Add a guided form for a new resource type
368
+
369
+ Add an entry to `RESOURCE_TEMPLATES` in `insight_tf.py`:
370
+
371
+ ```python
372
+ RESOURCE_TEMPLATES["aws_elasticache_cluster"] = {
373
+ "description": "ElastiCache Redis/Memcached cluster",
374
+ "fields": [
375
+ {"name": "resource_name", "label": "Resource name", "placeholder": "my_cache", "required": True, "default": ""},
376
+ {"name": "cluster_id", "label": "Cluster ID", "placeholder": "my-redis-cluster","required": True, "default": ""},
377
+ {"name": "engine", "label": "Engine", "placeholder": "redis", "required": True, "default": "redis"},
378
+ {"name": "node_type", "label": "Node type", "placeholder": "cache.t3.micro", "required": True, "default": "cache.t3.micro"},
379
+ {"name": "num_nodes", "label": "Num cache nodes","placeholder": "1", "required": True, "default": "1"},
380
+ ],
381
+ "template": '''resource "aws_elasticache_cluster" "{resource_name}" {{
382
+ cluster_id = "{cluster_id}"
383
+ engine = "{engine}"
384
+ node_type = "{node_type}"
385
+ num_cache_nodes = {num_nodes}
386
+ }}\n''',
387
+ }
388
+ ```
389
+
390
+ ### Add a new cloud provider
391
+
392
+ In the `PROVIDERS` list, add your entry with `"supported": True`:
393
+
394
+ ```python
395
+ {"id": "digitalocean", "name": "DigitalOcean", "icon": "🌊", "supported": True},
396
+ ```
397
+
398
+ Then handle the new provider ID in `on_provider_selected` inside `add_resource`:
399
+
400
+ ```python
401
+ if provider == "digitalocean":
402
+ self.app.push_screen(DOResourcePickerScreen(), on_resource_picked)
403
+ ```
404
+
405
+ ---
406
+
407
+ ## Troubleshooting
408
+
409
+ **`MountError: duplicate ID`**
410
+ A widget ID collision — ensure you are on the latest version. Run `git pull` and restart.
411
+
412
+ **`terraform not found`**
413
+ ```bash
414
+ which terraform # verify it's in PATH
415
+ terraform version # verify it runs
416
+ ```
417
+
418
+ **`infracost not found` in Cost Estimate**
419
+ ```bash
420
+ python setup.py # re-run to auto-install
421
+ ```
422
+
423
+ **`not authenticated` in Cost Estimate**
424
+ ```bash
425
+ infracost auth login
426
+ ```
427
+
428
+ **State not updating after apply / destroy**
429
+ Press `r` to manually reload. Ensure your backend writes a local `terraform.tfstate` or pull remote state first with `terraform state pull > terraform.tfstate`.
430
+
431
+ **App is slow to open the Add Resource wizard**
432
+ The catalog mounts 334 buttons at once. On very slow terminals, switch to the Manage tab first to let the app fully initialise before clicking Add Resource.
433
+
434
+ ---
435
+
436
+ ## Roadmap
437
+
438
+ - [ ] Multi-workspace support (`terraform workspace list / select`)
439
+ - [ ] Azure resource catalog (300+ resources)
440
+ - [ ] GCP resource catalog
441
+ - [ ] Kubernetes provider support
442
+ - [ ] `terraform output` viewer
443
+ - [ ] Module graph visualisation
444
+ - [ ] Remote state backend selector (S3, Terraform Cloud, GCS, Azure Blob)
445
+ - [ ] Import existing resources (`terraform import`)
446
+ - [ ] State move / rename (`terraform state mv`)
447
+ - [ ] Export cost report to CSV / PDF
448
+ - [ ] Dark / light theme toggle
449
+
450
+ ---
451
+
452
+ ## Contributing
453
+
454
+ 1. Fork the repository
455
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
456
+ 3. Make your changes and test: `textual run --dev insight_tf.py`
457
+ 4. Open a pull request with a clear description of what you changed
458
+
459
+ For new AWS resources, add entries to `AWS_RESOURCE_CATALOG`. For new guided forms, also add to `RESOURCE_TEMPLATES`. Please keep both in alphabetical order within their category.
460
+
461
+ ---
462
+
463
+ ## License
464
+
465
+ MIT — see [LICENSE](LICENSE) for details.
466
+
467
+ ---
468
+
469
+ <div align="center">
470
+ <sub>Built with ❤️ using <a href="https://textual.textualize.io/">Textual</a> and <a href="https://www.terraform.io/">Terraform</a></sub>
471
+ </div>