tfplan2md

repository·main·Indexed 41 days ago

https://github.com/oocx/tfplan2md

A utility that converts Terraform plan JSON files (generated via terraform show -json) into human-readable Markdown reports. Optimized for Pull Request reviews in GitHub and Azure DevOps, it provides logical grouping by module, semantic diffs, and support for SARIF 2.1.0 static analysis findings from tools like Checkov, Trivy, TFLint, and Semgrep.

Tokens
133.1K
Snippets
302
Records
590
Agent score
51%

What's inside tfplan2md

  1. What is tfplan2md?

    main

    tfplan2md is a tool that converts Terraform plan JSON files (generated via terraform show -json) into human-readable Markdown reports. It is designed to improve Pull Request reviews by providing structured, semantic diffs instead of raw JSON or verbose text output.

    Key benefits include:

    • Logical Grouping: Changes are grouped by module.
    • Semantic Diffs: Shows actual resource changes (e.g., adding/removing rules) rather than confusing index-based modifications.
    • Readability: Uses collapsible sections, tables, and semantic icons (e.g., 🌐 for IPs, 🛡️ for roles).
    • Security: Sensitive values are masked by default.
    • Integration: Works with GitHub and Azure DevOps PR comments and supports static analysis findings (SARIF 2.1.0) from tools like Checkov, Trivy, TFLint, and Semgrep.
  2. Overview of Website Design Prototypes

    main

    The tfplan2md website prototypes are divided into two main groups:

    Group A: Familiar Technical Documentation Sites

    These designs are inspired by established technical documentation platforms:

    • Design 1 (GitHub Docs Style): Clean, minimal, and technical with a light color scheme and blue accents. Located at design1/index.html.
    • Design 2 (Azure Docs Style): Professional, sidebar-based layout with breadcrumbs and tabbed code examples. Located at design2/index.html.
    • Design 3 (VS Code Docs Style): Dark mode, developer-focused three-column layout (sidebar + content + TOC). Located at design3/index.html.

    Group B: Unique/Alternative Designs

    These designs depart from traditional documentation layouts:

    • Design 4 (Minimalist Single-Page): Brutalist/Swiss style using monospace fonts, high contrast black/white, and a single-page scrolling design. Located at design4/index.html.
    • Design 5 (Interactive Terminal Theme): A retro/hacker aesthetic simulating a terminal window with green-on-black text and ASCII art. Located at design5/index.html.
    • Design 6 (Card-Based Modern): A contemporary, vibrant marketing style using gradients, glassmorphism, and large card layouts. Located at design6/index.html.

    Technical Specifications

    • Accessibility: All designs are responsive and follow WCAG 2.1 AA standards.
    • Dependencies: All designs use pure HTML/CSS with no external dependencies.
    • Logo Path: ../../assets/images/tfplan2md-logo.svg
  3. What is tfplan2md and its primary use cases?

    main

    tfplan2md is a CLI tool designed to convert Terraform plan JSON files into human-readable Markdown reports. Its primary purpose is to facilitate infrastructure change reviews within Pull Requests (PRs).

    Key Use Cases:

    • Pull Request Reviews: Generating clean, readable Markdown reports specifically optimized for rendering in GitHub Pull Request comments and Azure DevOps Pull Request comments.
    • CI/CD Integration: Running within Docker containers to automate the generation of infrastructure diffs during deployment pipelines.

    Core Capabilities:

    • Parses Terraform plan JSON output (generated via terraform show -json).
    • Groups resources by module hierarchy.
    • Provides semantic diffs for complex resources like firewall or NSG rules.
    • Automatically masks sensitive values for security.
  4. Use the Oocx.TfPlan2Md.HtmlRenderer tool

    main

    The Oocx.TfPlan2Md.HtmlRenderer is a standalone .NET console application designed to convert tfplan2md markdown reports into HTML. It provides two distinct rendering flavors to approximate how Markdown is displayed on specific platforms:

    1. GitHub Flavor: Mimics GitHub's security sanitization by stripping style attributes, adding accessibility wrappers to tables, and adding notranslate classes to code elements.
    2. Azure DevOps (AzDO) Flavor: Mimics Azure DevOps by preserving style attributes (useful for inline-diff rendering) and normalizing <details> tags.

    The tool supports applying wrapper templates using a {{content}} placeholder to wrap the generated HTML content.

  5. Refactoring Opportunities Report: Overview

    main
    This document outlines structural findings and recommended refactorings for the tfplan2md codebase. The report identifies six primary areas where architectural boundaries are failing, leading to high maintenance costs, regression risks, and difficulty in testing. The findings focus on improving the separation of concerns across report generation, provider extensions, platform-specific mapping, diagnostics, rendering, and internal tooling.
  6. Development Retrospective: TerraformShowRenderer

    main

    This document provides a retrospective on the development of the TerraformShowRenderer tool, which aims to produce output from Terraform plan JSON files that is 'authentically indistinguishable' from standard Terraform CLI output.

    Key Technical Challenges

    • Implicit Rule Deduction: AI models struggled to deduce implicit rendering rules such as whitespace, attribute ordering, and ANSI color patterns from examples alone.
    • Formatting Fidelity: Achieving high-fidelity output required intensive user-guided test strategies and iterative model switching.

    Successes

    • Fidelity: The final tool achieves 100% fidelity against Terraform's output.
    • Test Coverage: 33 new tests were added to ensure regression coverage for complex rendering logic.
    • Architecture: The tool was implemented as a standalone component to keep the main production library clean.
  7. Understand the Website2 Markdown Migration Status

    main

    The Website2 migration aims to move page bodies from legacy HTML (legacyContent shortcode) to native Eleventy Markdown and reusable components.

    Current State:

    • All 26 production routes are migrated to native Markdown sources.
    • Shared shell concerns (navigation, footer, theme toggle, etc.) are already migrated.
    • Interactive example fragments are located in website2/src/examples/.
    • The legacyContent dependency has been removed from all production routes.

    Active Migration Components: When authoring new or migrated pages, use these shared components:

    • hero-block
    • section-header
    • feature-detail
    • comparison-block
    • related-docs
    • code-window
    • feature-card
    • provider-card
    • example-block
  8. Website page structure and required pages

    main

    The website is organized into several key functional areas:

    • Homepage (/index.html): Features a hero section, problem/solution framing, feature highlights, and calls to action.
    • Features (/features/index.html): Contains dedicated pages for high-value features and a miscellaneous page for minor features.
    • Providers (/providers/index.html): Lists provider-specific templates (e.g., Azure).
    • Getting Started (/getting-started.html): Provides installation instructions (notably using docker run directly).
    • Documentation (/docs.html): Contains the CLI reference and template customization guides.
    • Examples (/examples.html): Displays real tfplan2md reports in both rendered and source (markdown) views.
    • Architecture (/architecture.html): Based on the arc42 documentation.
    • Contributing (/contributing.html): Details the contribution process and AI-driven development workflow.
  9. Overview of the tfplan2md website architecture

    main

    The website is the production site for tfplan2md, implemented as an Eleventy-based static site. It is designed to be easy for both humans and AI agents to maintain by using a markdown-friendly authoring model and minimizing markup repetition.

    Key Architectural Principles

    • Content-First Authoring: Pages are primarily authored in Markdown within website/src/.
    • Centralized Components: Reusable UI elements (Navbar, Footer, Hero blocks, etc.) are defined once and reused to prevent duplication.
    • Static Generation: The site is statically generated, with the final output residing in website/dist/.
    • Minimal Dependencies: The project avoids CSS frameworks and heavy JavaScript layout systems, preferring semantic HTML5 and native CSS features (Grid, Flexbox, Custom Properties).
    • Authoritative Sources: Content is derived from project sources like README.md, docs/, examples/, and artifacts/ rather than being manually duplicated.
  10. Overview of Design 6 Visual Variations

    main

    The Design 6 variations explore different color schemes and aesthetics while maintaining the same layout, structure, typography, and component design. Use these variations to select a visual direction for the project based on target audience and brand identity.

    Variation Details

    VariationThemePrimary ColorsBest For
    1. Blue/TechGitHub-inspiredBlue (#0969da), GreenTechnical audiences
    2. Dark ThemeModern Dark ModeDark (#0d1117), Blue (#58a6ff), Purple (#a371f7)Developers preferring dark mode
    3. TerraformBranded WarmthPurple (#7b42bc), Orange (#ff6b35)Terraform users
    4. MonochromeMinimalistBlack/White, Blue accent (#0066ff)High-contrast aesthetic
    5. Green/NatureEco-friendlyGreen (#16a34a)Environment-conscious feel
    6. Soft PastelsApproachableSoft Purple (#8b7cb8), Salmon (#e9967a)Less technical audiences
  11. Implement Phased Static Analysis Integration

    main

    The project uses a phased approach for adding static analyzers to minimize disruption and manage technical debt. When adding a new analyzer (like SonarAnalyzer.CSharp), follow this 9-task pattern:

    1. Add Package: Install the specific version of the analyzer package.
    2. Baseline: Identify and baseline existing violations.
    3. Configure: Set up rules in .editorconfig.
    4. Fix Critical: Resolve high-priority violations.
    5. Fix Non-Critical: Resolve lower-priority violations.
    6. Promote: Change critical rule severity from warning to error.
    7. Validate: Run existing test suites to ensure no regressions.
    8. Measure: Evaluate the impact on build performance.
    9. Finalize: Create the Pull Request for the phase completion.
  12. How output filenames and formats are determined

    main

    Output Filename Derivation

    If the --output parameter is not provided, the tool:

    1. Strips the .html extension from the input filename.
    2. Appends .png (the default format).
    3. Places the file in the same directory as the input.

    Example: report.html becomes report.png.

    Image Format Detection

    The tool determines the image format using the following priority:

    1. The explicit --format parameter (e.g., --format png).
    2. The file extension of the --output path (e.g., .jpg, .jpeg, .png).
    3. Defaults to png if neither is specified.