Architecture Overview¶
Purpose¶
tf-peek is a command-line tool that parses Terraform plan JSON files and generates
human-readable Markdown reports. It is designed to make reviewing terraform plan
output easier by producing a structured summary with per-resource diffs.
Core Principles¶
- Single responsibility: one command (
generate) that performs one task — convert a plan to a report. - Offline / local-only: no network calls, no databases. All processing happens on local files.
- Declarative configuration: a TOML file (
peek_config.toml) controls filtering and summarization per repository. - Structured data ingestion: the Terraform plan JSON is validated at parse time using Pydantic models.
- Separation of concerns: parsing, business logic, configuration, and rendering are each in their own module.
Code Organization¶
src/tf_peek/
├── __init__.py # Package marker
├── main.py # CLI definition and orchestration logic
├── models.py # Pydantic models for the Terraform plan JSON
├── config.py # Configuration loading (TOML → PeekConfig)
└── templates/
└── report.md.j2 # Jinja2 template that renders the Markdown report
Processing Pipeline¶
The generate command follows a linear pipeline:
- Load configuration — reads an optional
peek_config.toml(or a path supplied via--config). - Parse plan — deserializes the Terraform plan JSON into typed Pydantic models.
- Filter resources — resources whose type prefix matches
config.ignoreare skipped entirely; resources matchingconfig.summarizeare included but their attribute diff is hidden. - Classify actions — each
ResourceChangeis mapped to a simplified action:create,update,delete,replace, orno-op.no-opandreadresources are excluded. - Compute diffs — for non-summarized resources, before/after attribute values are compared;
values marked
after_unknownin the plan are rendered as(known after apply). - Render template — data is passed to a Jinja2 template that produces the final Markdown.
- Output — the rendered content is written to a file (if
--outputis specified) or printed to stdout viarich.
Key Dependencies¶
| Library | Role |
|---|---|
typer |
CLI argument parsing and command definition |
pydantic |
Runtime validation and typing of Terraform plan JSON |
jinja2 |
Markdown report templating |
rich |
Styled terminal output when writing to stdout |
tomllib |
Standard library TOML parser for reading peek_config.toml |