Last active
May 16, 2018 14:48
-
-
Save andytumelty/85d6b1bfa35e4113745096e1c3e38f94 to your computer and use it in GitHub Desktop.
Terraform: sensible diff for JSON objects
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
# E.g. Terraform IAM policies | |
terraform plan |\ | |
grep ' policy: ' |\ | |
sed 's/ *policy: *"\(.*\)" => "\(.*\)"/FROM\n\1\n%\nTO\n\2\n%/' |\ | |
sed 's/\\n/\n/g' | sed 's/\\"/"/g' |\ | |
gsplit -d -l 1 -t % - diff && \ | |
diff -y diff00 diff01 && \ | |
rm diff0* | |
# - assumes one thing is being compared, but you can trigger the diffs | |
# yourself to compare (diff00 and diff01 will be the first object, | |
# 02 and 03 will be the second, etc) | |
# - Line 11 is crappy -- this is to parse characters and escapes from | |
# the JSON, this would be better parsed through `print` | |
# - gsplit is GNU utils -- on GNU/Linux flavours you can sub for split |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment