Last active
January 30, 2019 22:13
-
-
Save jayers99/c697a364b9dbb44e82ce3be01ad42df5 to your computer and use it in GitHub Desktop.
Filter out all the security groups that have not changed from terraform plan output
This file contains hidden or 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
# getting close | |
cat ~/scripts/tfplan.sh | |
#!/usr/bin/env bash | |
planfile=$HOME/plans/${PWD##*/}_$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8) | |
planfilepr=$planfile'PR.md' | |
terraform plan "$@" | tee $planfile | |
# build a PR | |
sed -i "s,\x1B\[[0-9;]*[a-zA-Z],,g" $planfile | |
echo '## Terraform Plan' > $planfilepr | |
echo '### Change Summary' >> $planfilepr | |
grep --color=no -P '^Plan: ' $planfile >> $planfilepr | |
echo '```' >> $planfilepr | |
grep --color=no -P '^\s*[\+\-\~\/]{1,3} [^(create|update|destroy)]' $planfile >> $planfilepr | |
echo '```' >> $planfilepr | |
echo '### Change Details' >> $planfilepr | |
echo '```' >> $planfilepr | |
awk '/Terraform will perform the following actions:/{flag=1}/------------------------------------------------------------------------/{flag=0}flag' $planfile >> $planfilepr | |
echo '------------------------------------------------------------------------' >> $planfilepr | |
echo '```' >> $planfilepr | |
echo "plan has been copied to:" | |
echo $planfile | |
echo $planfilepr | |
terraform plan | gawk -F"\"" '$4 != $2 { print $0 }' | |
# remove color control chars | |
cat $planfile | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | |
# just adds | |
cat $planfile | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | grep -P '^\s*[\+\-\~]\s' | |
# adds and egress ingress | |
cat $planfile | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | grep -P '^\s*([\+\-\~]|ingress|egress)' | |
#!/usr/bin/env bash | |
planfile=$HOME/plans/${PWD##*/}_$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8).txt | |
terraform plan | tee $planfile | |
echo "plan has been copied to:" | |
echo $planfile | |
# just the plan part | |
awk '/Terraform will perform the following actions:/{flag=1}/Note: You didn/{flag=0}flag' $planfile | |
awk '/Terraform will perform the following actions:/{flag=1}/------------------------------------------------------------------------/{flag=0}flag' $planfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment