Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active March 29, 2019 01:13
Show Gist options
  • Save jayers99/31f45ecc3930632e5d983cd70f672a76 to your computer and use it in GitHub Desktop.
Save jayers99/31f45ecc3930632e5d983cd70f672a76 to your computer and use it in GitHub Desktop.
terraform plan policy differences
# final final
string=$(cat sample.txt | grep -P '^\s+policy:' | sed -r 's/\s*policy:\s*//g; s/\\n//g; s/\\\"/"/g; s/\s+//g; s/=>/\n/g')
IFS=$'\n' GLOBIGNORE='*' command eval 'array=($string)'
diff <(echo ${array[0]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.') <(echo ${array[1]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.') | grep -v "^[0-9c0-9]"
# sed file
s/\s*policy:\s*//g
s/\\n//g
s/\\\"/"/g
s/\s+//g
s/=>/\n/g
string=$(cat sample.txt | grep -P '^\s+policy:' | sed -r -f policy.sed)
IFS=$'\n' GLOBIGNORE='*' command eval 'array=($string)'
diff <(echo ${array[0]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.') <(echo ${array[1]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.')
# some old steps along the way
cat sample.txt | grep -P '^\s+policy:' | sed -r 's/\s*policy:\s*//g'
string=$(cat sample.txt | grep -P '^\s+policy:' | sed -r 's/\s*policy:\s*//g' | sed -r 's/\\n//g' | sed -r 's/\\\"/"/g' | sed -r 's/\s+//g' | sed -r 's/=>/\n/g')
IFS=$'\n' GLOBIGNORE='*' command eval 'array=($string)'
diff <(echo ${array[0]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.') <(echo ${array[1]} | sed -e 's/^"//g' -e 's/"$//g' | jq -S '.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment