Skip to content

Instantly share code, notes, and snippets.

@shashank-k
Forked from jamtur01/pre-commit
Created August 23, 2018 09:36
Show Gist options
  • Save shashank-k/f24a37c64917dcdd3d8949aa069327f6 to your computer and use it in GitHub Desktop.
Save shashank-k/f24a37c64917dcdd3d8949aa069327f6 to your computer and use it in GitHub Desktop.
A Terraform validation and formatting 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