Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .task/checksum/install
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b7ffb9a935aa0b08ea1c774c0758749
1603f214e5fa9a54e3841e5e0f5f7bf5
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Changelog

## [0.2.0] - 2024-06-15

### 🎨 Enhanced Output Formats and CLI Arguments

This release introduces multiple output formats and improved CLI arguments for better usability and integration capabilities.

### Major Changes

- **Multiple Output Formats:**
- Added support for three output formats:
- Console output (default): Colorized, human-readable format
- Markdown output: Structured markdown for documentation and code reviews
- JSON output: Machine-readable format for integration with other tools
- Each format maintains consistent data structure while optimizing for its use case

- **Improved CLI Arguments:**
- New output format options:
- `--output`: Choose between 'default', 'markdown', or 'json' formats
- `--detailed`: Show detailed resource information
- `--hide-changes`: Hide detailed attribute changes
- Deprecated arguments (with backward compatibility):
- `--changes` → Use `--hide-changes` instead
- `--details` → Use `--detailed` instead
- `--markdown` → Use `--output markdown` instead

- **Code Quality Improvements:**
- Refactored reporter implementation to follow DRY principles
- Centralized resource processing logic
- Improved test coverage for all output formats
- Enhanced error handling and validation

### Migration Notes

- The deprecated arguments will be removed in a future version
- Update your scripts and CI/CD pipelines to use the new argument names
- Consider using the JSON output format for better integration with other tools

---

## [0.1.0] - 2024-06-05

### 🎉 Project Reborn: tfsumpy 0.1.0
Expand Down
175 changes: 124 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ tfsumpy is a Python-based tool that summarizes Terraform plan files to provide a
## Features

- 🔍 Detailed plan analysis with change breakdown
- 📊 Clear summary statistics for resource changes
- 📊 Multiple output formats (default, markdown, JSON)
- 🔒 Automatic sensitive information redaction
- 🎨 Color-coded output for better readability
- 🔄 Detailed attribute change tracking
- 📝 Template-based markdown output
- 🔧 Extensible plugin system

## Installation

Expand All @@ -25,6 +27,7 @@ Or install from source:
cd tfsumpy
pip install .
```

## Usage

### Basic Usage
Expand All @@ -44,70 +47,158 @@ Basic summary:

Show detailed changes:
```bash
tfsumpy plan.json --changes
tfsumpy plan.json --hide-changes=false
```

Show resource details:
```bash
tfsumpy plan.json --details
tfsumpy plan.json --detailed
```

### Example Output
### Output Formats

tfsumpy supports three output formats:

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

2. Markdown:
```bash
Terraform Plan Analysis
======================
Total Changes: 3
Create: 1
Update: 1
Delete: 1
tfsumpy plan.json --output markdown
```

Resource Changes:
CREATE aws_s3_bucket: data_bucket
+ bucket = "new-bucket"
3. JSON:
```bash
tfsumpy plan.json --output json
```

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

DELETE aws_security_group: old_sg
- name = "old-sg"
#### 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"
```

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

Create a custom configuration file (config.json):
## 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"

### aws_instance.web_server
#### Changes:
- **instance_type**: "t2.micro" → "t2.small"

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

---
*Generated by tfsumpy on 2024-03-14 15:30:45*
```

#### 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": [
{
"sensitive_patterns": [
"type": "aws_s3_bucket",
"name": "data_bucket",
"action": "create",
"provider": "aws",
"module": "root",
"changes": [
{
"pattern": "\\b(?:password|secret|key)\\b",
"replacement": "[REDACTED]"
"attribute": "bucket",
"before": null,
"after": "new-bucket"
}
],
"risk_rules": {
"high": [
{
"pattern": "\\bdelete\\b.*\\b(database|storage)\\b",
"message": "Critical resource deletion"
}
]
}
]
}
]
}
```

### Deprecated Arguments

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):

```json
{
"sensitive_patterns": [
{
"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
tfsumpy plan.json --config config.json
```

### Debug Mode

For troubleshooting or detailed logging:

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

This will:
Expand Down Expand Up @@ -136,24 +227,6 @@ Please make sure to update tests as appropriate.

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

## Beta Markdown Output (New!)

You can generate a Markdown summary of your Terraform plan with:

```bash
tfsumpy plan.json --markdown > plan_summary.md
```

This will create a Markdown file with sections for summary, created, updated, and destroyed resources, and JSON code blocks for each resource change.

- **Created Resources**: 🟩
- **Updated Resources**: 🟦
- **Destroyed Resources**: 🟥

Each resource is shown as a JSON code block. For updates, both before and after states are shown.

> **Note:** Markdown output is a beta feature. Please report any issues or suggestions!
## Project Status

**Status:** Beta
Expand Down
42 changes: 36 additions & 6 deletions docs/api/reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

Reporters in **tfsumpy** are responsible for formatting and displaying the results of plan analysis. Each reporter implements a specific output format (e.g., CLI, Markdown, JSON). The primary built-in reporter is the `PlanReporter`, which provides human-friendly and Markdown output for Terraform plan summaries.
Reporters in **tfsumpy** are responsible for formatting and displaying the results of plan analysis. Each reporter implements a specific output format (e.g., CLI, Markdown, JSON). The primary built-in reporter is the `PlanReporter`, which provides multiple output formats for Terraform plan summaries.

---

Expand Down Expand Up @@ -36,26 +36,54 @@ class ReporterInterface(ABC):

## PlanReporter

The `PlanReporter` is the default reporter for plan summaries. It supports both colorized CLI output and Markdown output for sharing or documentation.
The `PlanReporter` is the default reporter for plan summaries. It supports three output formats:
- Console output (default)
- Markdown output (template-based)
- JSON output (structured)

**Example usage:**

```python
from tfsumpy.plan.reporter import PlanReporter

reporter = PlanReporter()

# Console output
reporter.print_report(plan_results, show_changes=True)

# Markdown output
reporter.print_report_markdown(plan_results, show_changes=True)

# JSON output
reporter.print_report_json(plan_results, show_changes=True)
```

**Parameters:**
- `data`: The analysis results (from `PlanAnalyzer`)
- `show_changes`: Show detailed attribute changes (bool)
- `show_details`: Show full resource details (bool)

**Output:**
- Prints formatted summary to stdout (or to a file/stream if specified)
- Markdown output is suitable for PRs, documentation, or compliance
**Output Formats:**

1. Console Output:
- Color-coded text
- Human-readable format
- Interactive terminal display

2. Markdown Output:
- Template-based formatting
- Summary statistics
- Resource changes
- Detailed information (if enabled)
- Timestamp and metadata

3. JSON Output:
- Structured data format
- Metadata (timestamp, version)
- Summary statistics
- Resource changes
- Detailed information (if enabled)
- Analysis results (if available)

---

Expand Down Expand Up @@ -84,6 +112,8 @@ Register your custom reporter with the tfsumpy `Context` to use it in your workf
---

## Notes
- The `PlanReporter` supports both CLI and Markdown output.
- The `PlanReporter` supports three output formats: console, markdown, and JSON.
- You can direct output to a file or stream by passing a custom `output` to `BaseReporter`.
- Markdown output uses Jinja2 templates for consistent formatting.
- JSON output provides a structured format suitable for integration with other tools.
- See the [Models API](models.md) for details on the data structures passed to reporters.
Loading