Skip to content

Instantly share code, notes, and snippets.

@mrcnc
Last active January 25, 2019 16:51
Show Gist options
  • Save mrcnc/5ce8509f908e6935aa4302ca68c64c5b to your computer and use it in GitHub Desktop.
Save mrcnc/5ce8509f908e6935aa4302ca68c64c5b to your computer and use it in GitHub Desktop.
git pre-commit hook to format terraform files
#!/usr/bin/env /bin/sh
set -e
files=$(git diff --cached --name-only --diff-filter=d)
for f in $files
do
if [ -e "$f" ] && [[ $f == *.tf ]]; then
printf "Formatting $f\n"
terraform fmt -check=true $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment