Skip to content

Commit

Permalink
Update doc and script/tfsum.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
containerscrew committed Apr 2, 2024
1 parent 5d2d931 commit 994d64f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
13 changes: 13 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Empty file removed internal/tui/.keep
Empty file.
32 changes: 17 additions & 15 deletions scripts/tfsum.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 994d64f

Please sign in to comment.