Last active
April 9, 2021 17:05
-
-
Save hermesespinola/652b9145906518959632dab48360510c to your computer and use it in GitHub Desktop.
Apply terraform fmt before a git commit
This file contains 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
TF_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.tf$') | |
if [ ! -z $TF_FILES ]; then | |
echo $TF_FILES | xargs -I'{}' -n1 sh -c "terraform fmt -list=false '{}'" | |
if [ $? -eq 1 ]; then | |
echo '⚠️ Aborting commit due to terraform errors' | |
exit 1 | |
else | |
echo '✨ Terraform files looking good' | |
echo $TF_FILES | xargs -I'{}' -n1 sh -c "git add '{}'" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment