diff --git a/README.md b/README.md index 6732bbf..9ebb0f0 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ tftools usage # TO DO +* When there are updates add flag --show-updates-output * Improve error handling * Add tests, although I have no experience * Code refactor is certainly needed! diff --git a/docs/usage.md b/docs/usage.md index 7207d60..42c5565 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -8,6 +8,7 @@ - [Function for fish](#function-for-fish) - [Function for bash](#function-for-bash) - [Load new functions](#load-new-functions) + - [Using tfsum as a custom binary](#using-tfsum-as-a-custom-binary) - [Example](#example) - [JSON output support](#json-output-support) - [JSON output with arns](#json-output-with-arns) @@ -114,6 +115,18 @@ source ~/.bashrc source ~/.config/fish/config.fish ``` +## Using tfsum as a custom binary + +Copy [tfsum](../scripts/tfsum.sh) to `/usr/local/bin/tfsum` + +```shell +sudo cp scripts/tfsum.sh /usr/local/bin/tfsum +``` + +> `/usr/local/bin` or other directory included in your path + +Inside the container image of [infratools](https://github.com/containerscrew/infratools), this custom binary is already contemplated. + # Example ```shell diff --git a/internal/tui/.keep b/internal/tui/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/tfsum.sh b/scripts/tfsum.sh old mode 100644 new mode 100755 index 881f9da..e977fde --- a/scripts/tfsum.sh +++ b/scripts/tfsum.sh @@ -1,15 +1,17 @@ -function tfsum() { - if [ -z "$1" ]; - then - echo "You should type 'tfsum terraform|terragrunt'" - else - echo -e "Starting tf summary..." - # Don't print output of terraform plan - # If you don't want full plan output: $1 plan -out plan.tfplan 1> /dev/null - $1 plan -out plan.tfplan - echo -e "\n" - $1 show -json plan.tfplan | tftools summarize - # Delete plan out file to avoid git tracking (although is included in .gitignore) - if [ -f "plan.tfplan" ]; then rm plan.tfplan; fi - fi -} +#!/bin/bash + +if [ -z "$1" ]; then + echo "You should type 'tfsum terraform|terragrunt'" + exit 1 +fi + +echo -en "Starting tf summary... Please wait" + +if [ -n "$2" ] && [ "$2" == "-v" ]; then + "$1" plan -out plan.tfplan +else + "$1" plan -out plan.tfplan 1> /dev/null +fi + +"$1" show -json plan.tfplan | tftools summarize --show-tags +if [ -f "plan.tfplan" ]; then rm plan.tfplan; fi \ No newline at end of file