-
-
Save norm/24cf10eb77734df32b7f66fe5d56b396 to your computer and use it in GitHub Desktop.
tf — terraform wrapper script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e -o pipefail | |
case "$1" in | |
plan) | |
terraform plan -out planfile | |
;; | |
apply) | |
if [ ! -f planfile ]; then | |
echo "No plan to apply -- run 'tf plan' first." | |
exit 1 | |
fi | |
terraform apply planfile \ | |
&& rm planfile | |
;; | |
diff) | |
input="$2" | |
if [ -z "$input" ]; then | |
if [ -t 0 ]; then | |
input="$(pbpaste)" | |
else | |
input="$(cat)" | |
fi | |
fi | |
IFS=$'\n' | |
for line in "$input"; do | |
pattern='^(?: *[a-z0-9_]+: *)?(".*") => (".*")$' | |
before=$( | |
echo "$line" \ | |
| perl -pe 'BEGIN { $/="" }; s{'"$pattern"'}{$1}sm;' \ | |
| jq -eS 'fromjson' | |
) | |
after=$( | |
echo "$line" \ | |
| perl -pe 'BEGIN { $/="" }; s{'"$pattern"'}{$2}sm;' \ | |
| jq -eS 'fromjson' | |
) | |
diff -u <(echo "$before") <(echo "$after") | |
done | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment