Skip to main content

A Python tool for Terraform state summary

Project description

tfsumpy - Terraform Plan Summary Tool

CI PyPI

tfsumpy is a Python-based tool that summarizes Terraform plan files to provide a clear overview of infrastructure changes. It helps DevOps teams review infrastructure changes more effectively by providing detailed plan summaries in different formats.

Features

  • 🔍 Detailed plan analysis with change breakdown
  • 📊 Clear summary statistics for resource changes
  • 🔒 Automatic sensitive information redaction
  • 🎨 Color-coded output for better readability
  • 🔄 Detailed attribute change tracking

Installation

Install using pip:

    pip install tfsumpy

Or install from source:

    git clone https://github.com/rafaelherik/tfsumpy.git
    cd tfsumpy
    pip install .

Usage

Basic Usage

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

Basic summary:

    tfsumpy plan.json

Show detailed changes:

    tfsumpy plan.json --changes

Show resource details:

    tfsumpy plan.json --details

Example 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

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

    tfsumpy plan.json --config config.json

Debug Mode

For troubleshooting or detailed logging:

    tfsumpy plan.json --debug

This will:

  • Enable verbose logging
  • Show detailed error messages
  • Display analysis process information

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 file for details.

Beta Markdown Output (New!)

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

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

Developer Workflow with Taskfile

This project uses Taskfile to simplify common development tasks.

Install Task

On macOS (with Homebrew):

brew install go-task/tap/go-task

On Linux:

sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d

Common Commands

  • Run all tests:
    task test
    
  • Build the package:
    task build
    
  • Run linting:
    task lint
    
  • Install all dependencies:
    task install
    

See all available tasks:

task --list

🧩 Extending tfsumpy (Plugins)

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

  • 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.

Example plugin:

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

Usage:

tfsumpy plan.json --plugin-dir my_plugins/

See Extending tfsumpy for more details and advanced examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfsumpy-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tfsumpy-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file tfsumpy-0.1.0.tar.gz.

File metadata

  • Download URL: tfsumpy-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tfsumpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4fafba638d1cd1ae55462afa43aac445b6c7056454deea4edf6734fb43748050
MD5 7ac5afc6d0764ae3b6d7379bbbc0c32d
BLAKE2b-256 f021ab293c274e4ea5b062f21910dc9817e8865f73c1ee26d81f303211da01aa

See more details on using hashes here.

File details

Details for the file tfsumpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tfsumpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tfsumpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccc7365a034129f6fc57ec72bdab2cb2f7b3e01597552a7314752bfab1d688a8
MD5 11d99d6d8da74fab14101260eec595a7
BLAKE2b-256 f144bc3083632d7dc5f748d5c24a8d915ef8bdf9c1e2accf142ae1eb7a765323

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page