Table of Contents generated with DocToc
terraform plan -out plan.tfplan
terraform show -json plan.tfplan | tftools summarize --show-tags --compact
Or if you have the file already in json:
terraform plan -out plan.tfplan
terraform show -json plan.tfplan > demo.json
cat plan.json | tftools summarize
# or
tftools summarize --compact --show-tags <demo.json
Edit your ~/.zshrc
function tfsum() {
if [ -z "$1" ];
then
echo "You should type 'tfsum terraform|terragrunt'"
else
echo -en "Starting tf summary... Please wait"
# If you want to print full plan output: $1 plan -out plan.tfplan
$1 plan -out plan.tfplan 1> /dev/null
$1 show -json plan.tfplan | tftools summarize --show-tags
# Delete plan out file to avoid git tracking (although is included in .gitignore)
if [ -f "plan.tfplan" ]; then rm plan.tfplan; fi
fi
}
Edit your ~/.config/fish/config.fish
or create a new file inside ~/.config/fish/functions/tfsum.fish
function tfsum
if test -z $argv[1]
echo "You should type 'tfsum terraform|terragrunt'"
else
echo -en "Starting tf summary... Please wait"
# If you want to print full plan output: $argv[1] plan -out plan.tfplan
$argv[1] plan -out plan.tfplan 1> /dev/null
$argv[1] show -json plan.tfplan | tftools summarize --show-tags
# Delete plan out file to avoid git tracking (although is included in .gitignore)
if test -f "plan.tfplan"; rm plan.tfplan; end
end
end
Edit your ~/.bashrc
tfsum() {
(
# Enable pipefail within the subshell
set -o pipefail
# Create plan and pass through any arguments
# Make a random tfplan filename in /tmp
TMP_FILE=$(mktemp /tmp/tfplan.XXXXXX)
# Execute terraform plan and other commands
terraform plan -lock=false -compact-warnings -out=${TMP_FILE} "$@" |
# Remove the line mentioning where the plan was saved
awk '!/Saved the plan to/{print;next} /Saved the plan to/{exit}' &&
terraform show -json ${TMP_FILE} |
tftools summarize --show-tags --show-unchanged --compact &&
rm ${TMP_FILE}
)
}
Warning
Adapt the rest of zsh, fish or bash functions according to your needs.
source ~/.zshrc
source ~/.bashrc
source ~/.config/fish/config.fish
Copy tfsum to /usr/local/bin/tfsum
sudo cp scripts/tfsum.sh /usr/local/bin/tfsum
/usr/local/bin
or other directory included in your path
cd my-terraform-project/
tfsum terraform
Then, you will see the summarized output with the corresponding targets.
The example:
Note
The following example is using the full output command
tftools summarize --show-tags --show-unchanged --compact <demo.json
Terragrunt is also supported
$ tfsum terragrunt
tftools summarize --json --pretty-json <demo.json
tftools summarize --json --metrics <demo.json
tftools summarize --json --metrics --pretty-json <demo.json