Skip to content

Instantly share code, notes, and snippets.

@srkiNZ84
Created September 28, 2018 04:33
Show Gist options
  • Save srkiNZ84/7ec17402a46c72e6649db49243441875 to your computer and use it in GitHub Desktop.
Save srkiNZ84/7ec17402a46c72e6649db49243441875 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -a ENVS_TO_PLAN=(test sandbox production)
for i in "${ENVS_TO_PLAN[@]}"; do
echo Planning environment: $i
cd $i
ls -al
echo Running Init for $i environment
aws-vault exec ident -- terraform init
echo Running Plan for $i environment
aws-vault exec ident -- terraform plan -no-color -out plan.out > $i-plan-output.txt
# Get rid of all contents before "------" line
echo Getting Raw TF into variable
RAWTF=`cat $i-plan-output.txt`
echo Sanitising TF to just get output
TFPLAN=${RAWTF#*------------------------------------------------------------------------}
echo Outputting plan to file for pasting
echo "$TFPLAN" > $i-plan.txt
# TODO Post to Slack
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment