Giter Club home page Giter Club logo

tf-summarize's Introduction

tf-summarize (Terraform Summarizer)

Build goreleaser GitHub release (latest SemVer)

tf-summarize is a command-line utility to print the summary of the terraform plan

Demo

demo

If demo is slower for you, please see examples and screenshot for more details

Why do we need it ?

  • 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.

Install

Using Go

go install github.com/dineshba/tf-summarize@latest

Using Brew

brew tap thecasualcoder/stable
brew install tf-summarize

Using Docker

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.

Download zip in release page

  1. Go to release page https://github.com/dineshba/terraform-plan-summary/releases
  2. Download the zip for your OS and unzip it
  3. Copy it to local bin using cp tf-summarize /usr/local/bin/tf-summarize or to location which is part of $PATH
  4. (For Mac Only) Give access to run if prompted. Refer here

Clone and Build Binary

  1. Clone this repo
  2. Build binary using make build or go build -o tf-summarize .
  3. Install it to local bin using make install or cp tf-summarize /usr/local/bin/tf-summarize

Usage

$ 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
  -out string
        [Optional] write output to file
  -separate-tree
        [Optional] print changes in tree format for each add/delete/change/recreate changes
  -tree
        [Optional] print changes in tree format
  -v    print version

Examples

# 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 -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

Github Actions Workflow

Please refer this sample github actions file and the sample runs here

Note: If you are using hashicorp/setup-terraform github action to setup terraform, ensure terraform_wrapper is set to false.

Comment terraform plan summary in PRs

Refer this example to add comments in your PR. Sample comment added by github actions bot.

Interactive summary review

You can use tool fx to review the summary fo the terraform change

tf-summarize -json tfplan | fx

Screenshot

screenshot

TODO

  • 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

tf-summarize's People

Contributors

czerasz avatar dineshba avatar triarius avatar zhilyaev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.