Skip to content

Instantly share code, notes, and snippets.

@mmh
Last active December 21, 2017 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmh/62f662bef7ed149f4f74745ffc9d0d55 to your computer and use it in GitHub Desktop.
Save mmh/62f662bef7ed149f4f74745ffc9d0d55 to your computer and use it in GitHub Desktop.
terraform fmt git pre-commit hook
#!/usr/bin/env bash
set -e
# Formats any *.tf files according to the hashicorp convention
files=$(git diff --cached --name-only)
for f in $files
do
if [ -e "$f" ] && [[ $f == *.tf ]]; then
#terraform validate `dirname $f`
terraform fmt $f
git add $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment