tf-summarize
is a command-line utility to print the summary of the terraform plan
If demo is slower for you, please see examples and screenshot for more details
- Most of the time, we make changes to the terraform files or tf-var files and run the plan command. And we precisely know which resources will get affected. In those time, we would like to just see the resource name and it's change.
- When our plan have more than say 10 changes, we will first see what are the deleted changes, or we will just see the list of resources that get affected.
go install github.com/dineshba/tf-summarize@latest
brew tap thecasualcoder/stable
brew install tf-summarize
asdf plugin add tf-summarize
asdf install tf-summarize latest
See the asdf plugin source for more information.
docker run -v $PWD:/workspace -w /workspace ghcr.io/dineshba/tf-summarize -v # prints version
docker run -v $PWD:/workspace -w /workspace ghcr.io/dineshba/tf-summarize tfplan.json
docker run -v $PWD:/workspace -w /workspace ghcr.io/dineshba/tf-summarize -tree tfplan.json
# see example section for more examples
# add alias if needed
alias tf-summarize="docker run -v $PWD:/workspace -w /workspace ghcr.io/dineshba/tf-summarize"
tf-summarize tfplan.json
# see example section for more examples
tf-summarize will accept tfplan directly. Docker based tf-summarize is not having terraform-binary to convert tfplan to json. So it only works with json files. If you want to use with tfplan directly, You can build a base image with terraform (use same version as tfplan created) and have our binary in it.
The below example uses kishaningithub/setup-tf-summarize
steps:
- uses: kishaningithub/setup-tf-summarize@v1
For more customization options, kindly refer to the documentation here
- Go to release page https://github.com/dineshba/terraform-plan-summary/releases
- Download the zip for your OS and unzip it
- Copy it to local bin using
cp tf-summarize /usr/local/bin/tf-summarize
or to location which is part of$PATH
- (For Mac Only) Give access to run if prompted. Refer here
- Clone this repo
- Build binary using
make build
orgo build -o tf-summarize .
- Install it to local bin using
make install
orcp tf-summarize /usr/local/bin/tf-summarize
$ tf-summarize -h
Usage of tf-summarize [args] [tf-plan.json|tfplan]
-draw
[Optional, used only with -tree or -separate-tree] draw trees instead of plain tree
-html
[Optional] print changes in html format
-json
[Optional] print changes in json format
-json-sum
[Optional] print summary in json format
-md
[Optional, used only with table view] output table as markdown
-out string
[Optional] write output to file
-separate-tree
[Optional] print changes in tree format for add/delete/change/recreate changes
-tree
[Optional] print changes in tree format
-v print version
# run terraform plan command
terraform plan -out=tfplan
# provide plan itself directly
tf-summarize tfplan # summary in table format
tf-summarize -tree tfplan # summary in tree format
tf-summarize -tree -draw tfplan # summary in 2D tree format
tf-summarize -json tfplan # summary in json format
tf-summarize -json-sum tfplan # summary of changes in json format
tf-summarize -separate-tree tfplan # summary in separate tree format
tf-summarize -separate-tree -draw tfplan # summary in separate 2D tree format
tf-summarize -out=summary.md tfplan # summary in output file instead of stdout
# provide json output from plan
terraform show -json tfplan | tf-summarize # summary in table format
terraform show -json tfplan > output.json
tf-summarize output.json # summary in table format
The below example uses kishaningithub/setup-tf-summarize
name: Run tf-summarize
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: kishaningithub/setup-tf-summarize@v1
- name: Print tf-summarize version and help
run: |
tf-summarize -v
tf-summarize -h
For more customization options, kindly refer to the documentation here
Please refer this sample GitHub actions file and the sample runs here
Note: If you are using
hashicorp/setup-terraform
GitHub action to set up terraform, ensure terraform_wrapper is set to false.
The below assumes that you have a stage called show
in your codefresh.yaml
example
We need to output the plan to json as there were some strange issues on codefresh when we used the tfplan
file
A full example is available at example/codefresh/codefresh.yaml
TerraformPlan:
title: Terraform Plan
image: hashicorp/terraform:light
stage: plan
working_directory: "${{clone}}"
commands:
- terraform plan -out=tfplan
- terraform show -json tfplan > output.json
tfSummarize:
title: Show Changes
image: ghcr.io/dineshba/tf-summarize
stage: show
working_directory: "${{clone}}"
commands:
- tf-summarize output.json
⚠️ Not maintained by dineshba : The above example is maintained by userbradley - Any questions related please tag@userbradley
on an issue
Refer this example to add comments in your PR. Sample comment added by github actions bot.
You can use tool fx to review the summary fo the terraform change
tf-summarize -json tfplan | fx
- Read terraform state file directly. (Currently need to convert to json and pass it)
- Directly run the terraform plan and show the summary
- Able to show summary of the current terraform state
- Include version subcommand in binary