Created
April 9, 2018 16:38
-
-
Save ashb/a6425709bb8a32ed3f2720aea0b445d8 to your computer and use it in GitHub Desktop.
Show a diff of single line JSON objects (IAM policy docs) in terraform
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 | |
# | |
# shellcheck disable=SC2001 | |
set -e -o pipefail | |
input="$1" | |
[[ -n "$input" ]] || { | |
[[ -t 0 ]] && { input="$(pbpaste)"; } || input="$(cat)" | |
} | |
# TODO: Deal with multiple lines in the input. | |
pattern='^(?: *[a-z0-9_]+: *)?(".*") => (".*")$' | |
before=$(echo "$input" | perl -p -e 'BEGIN { $/="" }; s/'"$pattern"'/$1/sm;' | jq -eS 'fromjson') | |
after=$(echo "$input" | perl -p -e 'BEGIN { $/="" }; s/'"$pattern"'/$2/sm;' | jq -eS 'fromjson') | |
diff -u <(echo "$before") <(echo "$after") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment