Created
May 27, 2020 17:34
-
-
Save Y-LyN-10/ee647cb835db2166c02e46c2703ad8e9 to your computer and use it in GitHub Desktop.
Quick check to see if my terraform code is applied and/or there are any drifts
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 | |
YELLOW='\033[1;33m' | |
GREEN='\033[0;32m' | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
drift_check() { | |
dir="$(basename $PWD)" | |
output="$(terraform plan -detailed-exitcode)"; | |
code="$?" | |
if [[ $code -eq 0 ]] ; then | |
echo -e "${GREEN}$dir:Infrastructure is up-to-date.${NC}" | |
fi | |
if [[ $code -eq 2 ]] ; then | |
echo -e "${YELLOW}$dir:Drift Detected!${NC}" | |
fi | |
if [[ $code -eq 1 ]] ; then | |
echo -e "${RED}$dir:ERROR in Terraform Plan!${NC}" | |
fi | |
} | |
dirs=($(find . -maxdepth 1 -type d \( ! -name . \))) | |
root="$(pwd)" | |
for dir in "${dirs[@]}"; do | |
cd "$dir" | |
drift_check & | |
cd $root | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment