Skip to content

Instantly share code, notes, and snippets.

@jmoberly
Last active April 29, 2016 17:23
Show Gist options
  • Save jmoberly/34698face6bcba94a95f9ea32e0d4775 to your computer and use it in GitHub Desktop.
Save jmoberly/34698face6bcba94a95f9ea32e0d4775 to your computer and use it in GitHub Desktop.
Terraform git pre-commit hook
#!/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