Skip to content

Instantly share code, notes, and snippets.

@jayers99
Last active March 5, 2019 00:54
Show Gist options
  • Save jayers99/841dde005638bf128cded1bd521bc743 to your computer and use it in GitHub Desktop.
Save jayers99/841dde005638bf128cded1bd521bc743 to your computer and use it in GitHub Desktop.
terraform plan multiple directories
#!/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