tf-plan-summary

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

tf-plan-summary

ci go license

Turn noisy terraform plan output into a clean, reviewable PR comment.

tf-plan-summary reads a terraform show -json plan, groups the resource changes by action, and renders a compact Markdown summary. As a GitHub Action it posts one sticky comment that refreshes in place on every push — so a PR shows the current plan, not a pile of stale ones.

## Terraform Plan Summary

**2** to add, **1** to change, **1** to replace, **1** to destroy.

> ⚠️ Review carefully: 1 to replace, 1 to destroy.

<details><summary>Details (5 resources)</summary>
| Action | Resource | Type |
| + create | aws_s3_bucket.assets | aws_s3_bucket |
| ± replace | aws_instance.web | aws_instance |
| - destroy | aws_db_instance.legacy | aws_db_instance |
</details>

What it does

  • Parses terraform show -json plan.bin into per-resource actions.
  • Classifies each as create / update / replace / destroy (a create+delete pair, in either order, is a replacement), ignoring no-op and read.
  • Renders counts, a collapsible details table, and a risk callout whenever the plan replaces or destroys anything.
  • Exit code stays 0 for a clean render; wire the threshold gate in CI as you like.

Use it as a GitHub Action

permissions:
  contents: read
  pull-requests: write

steps:
  - uses: actions/checkout@v4
  - uses: hashicorp/setup-terraform@v3
  - run: |
      terraform init -input=false
      terraform plan -out=plan.bin -input=false
      terraform show -json plan.bin > plan.json
  - uses: moveeeax/tf-plan-summary@v1
    with:
      plan-json: plan.json
      github-token: ${{ secrets.GITHUB_TOKEN }}

The action finds its previous comment by a hidden marker and edits it, so re-runs never spam the thread. See examples/ for a full workflow.

Use it as a CLI

go install github.com/moveeeax/tf-plan-summary@latest

# render to stdout
tf-plan-summary --plan-json plan.json

# post/refresh a sticky comment
tf-plan-summary --plan-json plan.json --repo owner/name --pr 42 --github-token "$GITHUB_TOKEN"
Flag Default Description
--plan-json — Path to terraform show -json output (required)
-o, --output - Write Markdown to a file instead of stdout
--marker <!-- tf-plan-summary --> Hidden marker identifying the sticky comment
--github-token $GITHUB_TOKEN Token for posting the comment
--repo $GITHUB_REPOSITORY owner/name of the repository
--pr $PR_NUMBER Pull request number

Comment posting happens only when token, repo, and PR number are all set; otherwise it just renders the Markdown.

How it works

The plan parser reads resource_changes[].change.actions and collapses the array into one effective action — the only subtlety is that Terraform expresses a replacement as ["create","delete"] (or the reverse), which is detected explicitly. The sticky-comment logic sits behind a small Commenter interface, so the create-vs-update decision is unit-tested without touching the GitHub API; the real implementation uses go-github.

Development

make build   # go build -o tf-plan-summary .
make test    # go test -race ./...
make lint    # gofmt -l . && go vet ./...

License

MIT — see LICENSE.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package cmd wires the tf-plan-summary CLI.
Package cmd wires the tf-plan-summary CLI.
internal
comment
Package comment upserts a single sticky PR comment identified by a marker.
Package comment upserts a single sticky PR comment identified by a marker.
plan
Package plan parses a `terraform show -json` plan into grouped resource actions.
Package plan parses a `terraform show -json` plan into grouped resource actions.
render
Package render turns a plan Summary into a Markdown PR comment.
Package render turns a plan Summary into a Markdown PR comment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL