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
23 changes: 23 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version, and other tools you might need
build:
os: ubuntu-24.04
tools:
python: "3.13" # Note: 3.13 is very new, consider using 3.11 for better compatibility

# Build documentation with Mkdocs
mkdocs:
configuration: mkdocs.yml

# Optionally, but recommended,
# declare the Python requirements required to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt

32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# TFSumPy - Terraform Plan Analyzer
# bolwerk - Terraform Plan Analyzer

[![CI](https://github.com/rafaelherik/tfsumpy/actions/workflows/ci.yaml/badge.svg)](https://github.com/rafaelherik/tfsumpy/actions/workflows/ci.yaml)
[![CI](https://github.com/rafaelherik/bolwerk/actions/workflows/ci.yaml/badge.svg)](https://github.com/rafaelherik/bolwerk/actions/workflows/ci.yaml)

TFSumPy is a Python-based tool that analyzes Terraform plan files to provide a clear summary of infrastructure changes and identify potential risks. It helps DevOps teams review infrastructure changes more effectively by:
bolwerk is a Python-based tool that analyzes Terraform plan files to provide a clear summary of infrastructure changes and identify potential risks. It helps DevOps teams review infrastructure changes more effectively by:

- Summarizing resource changes (create, update, delete)
- Identifying high and medium risk changes
Expand All @@ -23,12 +23,12 @@ TFSumPy is a Python-based tool that analyzes Terraform plan files to provide a c

Install using pip:
```bash
pip install tfsumpy
pip install bolwerk
```
Or install from source:
```bash
git clone https://github.com/rafaelherik/tfsumpy.git
cd tfsumpy
git clone https://github.com/rafaelherik/bolwerk.git
cd bolwerk
pip install .
```
## Usage
Expand All @@ -45,27 +45,27 @@ Or install from source:

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

Show detailed changes:
```bash
tfsumpy plan.json --changes
bolwerk plan.json --changes
```

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

Enable risk assessment:
```bash
tfsumpy plan.json --risks
bolwerk plan.json --risks
```

Enable policy compliance check:
```bash
tfsumpy plan.json --policies
bolwerk plan.json --policies
```

### Example Output
Expand Down Expand Up @@ -93,7 +93,7 @@ Enable policy compliance check:
1. Risk Assessment:

```bash
tfsumpy plan.json --risks
bolwerk plan.json --risks
```

This will show:
Expand All @@ -104,7 +104,7 @@ This will show:
2. Policy Compliance:

```bash
tfsumpy plan.json --policies
bolwerk plan.json --policies
```

Checks resources against:
Expand All @@ -115,7 +115,7 @@ Checks resources against:
3. Detailed Analysis:

```bash
tfsumpy plan.json --changes --details --risks
bolwerk plan.json --changes --details --risks
```

### Configuration
Expand Down Expand Up @@ -144,15 +144,15 @@ Create a custom configuration file (config.json):
Use the configuration:

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

### Debug Mode

For troubleshooting or detailed logging:

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

This will:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions tfsumpy/db/manager.py → bolwerk/db/manager.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from typing import Dict, List, Optional
import logging
from pathlib import Path

def __init__(self, db_path: str = None):

import sqlite3
from pathlib import Path
import json
import logging

class DBManager:
"""Global database manager for TFSumPy."""
"""Global database manager for bolwerk."""

def __init__(self, db_path: str = None):
if not db_path:
db_path = str(Path.home() / '.tfsumpy' / 'tfsumpy.db')
db_path = str(Path.home() / '.bolwerk' / 'bolwerk.db')

Path(db_path).parent.mkdir(parents=True, exist_ok=True)
self.db_path = db_path
Expand Down
File renamed without changes.
29 changes: 24 additions & 5 deletions tfsumpy/plan/reporter.py → bolwerk/plan/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,21 @@ def _print_summary(self, report: Dict) -> None:

def _print_resource_details(self, resources: list, show_changes: bool = False) -> None:
"""Format the resource details section."""
self._write(f"\n{self._colorize('Resource Changes:', 'bold')}\n")
self._write(f"\n{self._colorize('Resources Changes:', 'bold')}\n")

# Define color mapping for actions
action_colors = {
'CREATE': 'green',
'UPDATE': 'blue',
'DELETE': 'red'
}

for resource in resources:
action_str = resource['action'].upper()
# Color the action string based on the action type
colored_action = self._colorize(action_str, action_colors.get(action_str, 'bold'))
self._write(
f"\n{action_str} {resource['resource_type']}: "
f"\n{colored_action} {resource['resource_type']}: "
f"{resource['identifier']}\n"
)

Expand All @@ -97,16 +106,26 @@ def _print_attribute_changes(self, resource: Dict) -> None:
all_attrs = set(before.keys()) | set(after.keys())
skip_attrs = {'id', 'tags_all'} # Skip internal attributes

# Define color mapping for symbols
symbol_colors = {
'+': 'green', # create
'~': 'blue', # update
'-': 'red' # delete
}

for attr in sorted(all_attrs - skip_attrs):
before_val = before.get(attr)
after_val = after.get(attr)

if before_val != after_val:
if resource['action'] == 'create':
lines.append(f" + {attr} = {after_val}")
symbol = self._colorize('+', symbol_colors['+'])
lines.append(f" {symbol} {attr} = {after_val}")
elif resource['action'] == 'delete':
lines.append(f" - {attr} = {before_val}")
symbol = self._colorize('-', symbol_colors['-'])
lines.append(f" {symbol} {attr} = {before_val}")
else: # update
lines.append(f" ~ {attr} = {before_val} -> {after_val}")
symbol = self._colorize('~', symbol_colors['~'])
lines.append(f" {symbol} {attr} = {before_val} -> {after_val}")

self._write('\n'.join(lines))
File renamed without changes.
2 changes: 2 additions & 0 deletions bolwerk/policies/azuread.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
provider: azuread
policies:
3 changes: 3 additions & 0 deletions bolwerk/policies/azurerm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider: azurerm
policies:

2 changes: 1 addition & 1 deletion tfsumpy/policy/__init__.py → bolwerk/policy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Policy module for TFSumPy.
"""Policy module for bolwerk.

This module provides policy management functionality including policy loading,
database management, and policy evaluation.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def load_default_policies(self) -> None:
"""Load all default policies from package data."""
try:
# Get all policy files from package data
policy_files = pkg_resources.resource_listdir('tfsumpy', 'policies')
policy_files = pkg_resources.resource_listdir('bolwerk', 'policies')

for filename in policy_files:
if filename.endswith('.yaml'):
policy_content = pkg_resources.resource_string(
'tfsumpy', f'policies/{filename}'
'bolwerk', f'policies/{filename}'
).decode('utf-8')

try:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class BaseReporter:
'high': Fore.RED,
'medium': Fore.YELLOW,
'low': Fore.GREEN,
'green': Fore.GREEN,
'blue': Fore.BLUE,
'red': Fore.RED,
'reset': Style.RESET_ALL,
'bold': Style.BRIGHT
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tfsumpy/risk/analyzer.py → bolwerk/risk/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _load_provider_analyzers(self) -> None:

for module_info in pkgutil.iter_modules([str(providers_path)]):
try:
module = importlib.import_module(f".providers.{module_info.name}", package="tfsumpy.risk")
module = importlib.import_module(f".providers.{module_info.name}", package="bolwerk.risk")
for attr_name in dir(module):
attr = getattr(module, attr_name)
if (isinstance(attr, type) and
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ def _check_deletion_risks(self, change: ResourceChange) -> List[RiskFinding]:
mitigation="Verify all resource dependencies before deletion"
)]

# ... implement other check methods similarly ...
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions docs/DEFAULT_POLICIES.md

This file was deleted.

Loading
Loading