Skip to content

Instantly share code, notes, and snippets.

@Y-LyN-10
Created May 27, 2020 17:34
Show Gist options
  • Save Y-LyN-10/ee647cb835db2166c02e46c2703ad8e9 to your computer and use it in GitHub Desktop.
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
#!/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