Last active
March 5, 2019 00:54
-
-
Save jayers99/841dde005638bf128cded1bd521bc743 to your computer and use it in GitHub Desktop.
terraform plan multiple directories
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
#!/bin/bash | |
# get the root repo directory | |
repo_dir=$(git rev-parse --show-toplevel) | |
# creast a list of directories to run the plan against | |
dirs=$(ls -d $repo_dir/network/vpc*) | |
# set the report file name | |
mkdir -p $HOME/reports/ | |
report_file=$HOME/reports/vpc_sg_counts_$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8) | |
#loop through dirs and append the report file | |
for i in $dirs; | |
do | |
echo $i | tee -a $report_file | |
cd $i | |
terraform plan | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' | grep --color=no -P '(^\s*[\+\-\~\/]{1,3} module.vpc.aws_security_group)|(^\s*(egress|ingress)\.#)' | tee -a $report_file | |
# ^^^ remove all the color | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment