Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,5 @@ Pipfile.lock
poetry.lock

# cursor rules
.cursorrules
.cursor/rules
.task/
1 change: 0 additions & 1 deletion .task/checksum/install

This file was deleted.

29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Changelog

## [0.3.0] - 2025-06-16

### 🚀 New Features

- Added AI-driven plan analysis agent (PlanAnalysisAgent) with Azure context integration.
- Introduced `replace` attribute capture in plan analyzer for accurate reporting of resource replacements.
- Flattened single-element action lists in plan analysis to simplify actions representation.

### 🐛 Bug Fixes

- Skipped no-op changes properly in plan analyzer to avoid redundant entries.
- Fixed reporting of replacement operations in plan reporter.

### 📖 Documentation Improvements

- Updated README and documentation for AI analysis and enhanced command-line usage.
- Refreshed advanced usage and API docs to reflect new features and configurations.

### ⬆️ Dependencies

- Added `backoff` for improved retry and error handling.

### ⚙️ Other Changes

- Removed deprecated `scripts/install_ai_deps.sh`.
- Refactored base reporter and context management for consistency.

---

## [0.2.0] - 2024-06-15

### 🎨 Enhanced Output Formats and CLI Arguments
Expand Down
282 changes: 61 additions & 221 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,161 +12,63 @@ tfsumpy is a Python-based tool that summarizes Terraform plan files to provide a
- 🔒 Automatic sensitive information redaction
- 🎨 Color-coded output for better readability
- 🔄 Detailed attribute change tracking
- ♻️ Replacement detection: flags resources being recreated and shows enforcing attributes
- 📝 Template-based markdown output
- 🔧 Extensible plugin system
- 🤖 AI-powered change summarization (OpenAI, Gemini, Anthropic)

## Installation

Install using pip:
```bash
pip install tfsumpy
pip install tfsumpy
```
Or install from source:
```bash
git clone https://github.com/rafaelherik/tfsumpy.git
cd tfsumpy
pip install .
```

## Usage

### Basic Usage
## Quick Start

1. Generate a Terraform plan JSON file:
```bash
terraform plan -out=tfplan
terraform show -json tfplan > plan.json
terraform plan -out=tfplan
terraform show -json tfplan > plan.json
```

2. Analyze the plan:

Basic summary:
```bash
tfsumpy plan.json
```
# Basic summary
tfsumpy plan.json

Show detailed changes:
```bash
tfsumpy plan.json --hide-changes=false
```
# Hide attribute changes (optional)
tfsumpy plan.json --hide-changes

Show resource details:
```bash
tfsumpy plan.json --detailed
# Show detailed resource information (with attribute changes)
tfsumpy plan.json --detailed
```

### Output Formats
## Output Formats

tfsumpy supports three output formats:

1. Default (console output):
```bash
tfsumpy plan.json
```
# Default console output
tfsumpy plan.json

2. Markdown:
```bash
tfsumpy plan.json --output markdown
```
# Markdown output
tfsumpy plan.json --output markdown

3. JSON:
```bash
tfsumpy plan.json --output json
# JSON output
tfsumpy plan.json --output json
```

### Example Outputs

#### Default Output
```
Terraform Plan Analysis
======================
Total Changes: 3
Create: 1
Update: 1
Delete: 1

Resource Changes:
CREATE aws_s3_bucket: data_bucket
+ bucket = "new-bucket"

UPDATE aws_instance: web_server
~ instance_type = t2.micro -> t2.small

DELETE aws_security_group: old_sg
- name = "old-sg"
```

#### Markdown Output
```markdown
# Terraform Plan Analysis Report

## Summary
- **Total Resources**: 3
- **Resources to Add**: 1
- **Resources to Change**: 1
- **Resources to Destroy**: 1

## Resource Changes
### aws_s3_bucket.data_bucket
#### Changes:
- **bucket**: null → "new-bucket"
## AI Summarization

### aws_instance.web_server
#### Changes:
- **instance_type**: "t2.micro" → "t2.small"
Enable AI-powered change summarization using OpenAI:

### aws_security_group.old_sg
#### Changes:
- **name**: "old-sg" → null

---
*Generated by tfsumpy on 2024-03-14 15:30:45*
```
```bash
# Using OpenAI
tfsumpy plan.json --output markdown --ai openai YOUR_API_KEY

#### JSON Output
```json
{
"metadata": {
"timestamp": "2024-03-14T15:30:45.123456",
"version": "1.0",
"format": "json"
},
"summary": {
"total_resources": 3,
"resources_to_add": 1,
"resources_to_change": 1,
"resources_to_destroy": 1
},
"resources": [
{
"type": "aws_s3_bucket",
"name": "data_bucket",
"action": "create",
"provider": "aws",
"module": "root",
"changes": [
{
"attribute": "bucket",
"before": null,
"after": "new-bucket"
}
]
}
]
}
```

### Deprecated Arguments
## Configuration

The following arguments are deprecated and will be removed in a future version:

- `--changes` → Use `--hide-changes=false` instead
- `--details` → Use `--detailed` instead
- `--markdown` → Use `--output markdown` instead

### Configuration

Create a custom configuration file (config.json):
Create a `config.json` file to customize behavior:

```json
{
Expand All @@ -175,123 +77,61 @@ Create a custom configuration file (config.json):
"pattern": "\\b(?:password|secret|key)\\b",
"replacement": "[REDACTED]"
}
],
"risk_rules": {
"high": [
{
"pattern": "\\bdelete\\b.*\\b(database|storage)\\b",
"message": "Critical resource deletion"
}
]
}
]
}
```

Use the configuration:

```bash
tfsumpy plan.json --config config.json
```

### Debug Mode

For troubleshooting or detailed logging:

```bash
tfsumpy plan.json --debug
```
## Extending tfsumpy

This will:
- Enable verbose logging
- Show detailed error messages
- Display analysis process information
tfsumpy supports plugins for custom analyzers and reporters. Create a Python file in the `plugins/` directory:

## Requirements

- Python 3.10 or higher
- Terraform 1.0 or higher

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes:

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

Please make sure to update tests as appropriate.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Project Status

**Status:** Beta

## Developer Workflow with Taskfile

This project uses [Taskfile](https://taskfile.dev) to simplify common development tasks.
```python
from tfsumpy.analyzer import AnalyzerInterface, AnalyzerResult

### Install Task
class MyAnalyzer(AnalyzerInterface):
@property
def category(self):
return "custom"

def analyze(self, context, **kwargs):
return AnalyzerResult(
category="custom",
data={"result": "analysis"}
)

On macOS (with Homebrew):
```bash
brew install go-task/tap/go-task
```
On Linux:
```bash
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
def register(context):
context.register_analyzer(MyAnalyzer())
```

### Common Commands

- Run all tests:
```bash
task test
```
- Build the package:
```bash
task build
```
- Run linting:
```bash
task lint
```
- Install all dependencies:
```bash
task install
```

See all available tasks:
Load custom plugins:
```bash
task --list
tfsumpy plan.json --plugin-dir my_plugins/
```

## 🧩 Extending tfsumpy (Plugins)
## Development

tfsumpy supports plug-and-play extensions! You can add your own analyzers or reporters by dropping Python files in a `plugins/` directory (or specify a custom directory with `--plugin-dir`).
This project uses [Taskfile](https://taskfile.dev) for development tasks:

- Each plugin should define a `register(context)` function that registers analyzers/reporters.
- tfsumpy will automatically load and register all plugins in the directory at startup.
```bash
# Install dependencies
task install

**Example plugin:**
```python
from tfsumpy.analyzer import AnalyzerInterface, AnalyzerResult
class MyCostAnalyzer(AnalyzerInterface):
@property
def category(self): return "cost"
def analyze(self, context, **kwargs):
return AnalyzerResult(category="cost", data={"total_cost": 42})
def register(context):
context.register_analyzer(MyCostAnalyzer())
```
# Run tests
task test

**Usage:**
```bash
tfsumpy plan.json --plugin-dir my_plugins/
# Run linting
task lint
```

See [Extending tfsumpy](docs/extending.md) for more details and advanced examples.
## Documentation

For detailed documentation, visit our [documentation site](https://tfsumpy.readthedocs.io/).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Loading