Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ibrahima
Forked from jamtur01/pre-commit
Last active August 9, 2018 19:03
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 ibrahima/1a4c0a3369e590715988f1390b4effdd to your computer and use it in GitHub Desktop.
Save ibrahima/1a4c0a3369e590715988f1390b4effdd 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 --diff-filter=d)
for f in $files
do
if [ -e "$f" ] && [[ $f == *.tf ]]; then
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