Last active
April 29, 2016 17:23
-
-
Save jmoberly/34698face6bcba94a95f9ea32e0d4775 to your computer and use it in GitHub Desktop.
Terraform git pre-commit hook
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
#!/bin/bash | |
# | |
# Validates terraform templates before commit | |
set -e | |
terraform validate stacks/vpc | |
terraform validate stacks/environment | |
terraform validate stacks/pod | |
# 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 fmt $f | |
git add -p $f | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment