Skip to content

Instantly share code, notes, and snippets.

@miry
Last active October 4, 2018 18:58
Show Gist options
  • Save miry/3db93ae3f76cb56c3689a2bf355ff1ee to your computer and use it in GitHub Desktop.
Save miry/3db93ae3f76cb56c3689a2bf355ff1ee to your computer and use it in GitHub Desktop.
Terraform and Packer project hooks

Usage per project:

curl "https://gist.githubusercontent.com/miry/3db93ae3f76cb56c3689a2bf355ff1ee/raw/post-merge" > .git/hooks/post-merge
curl "https://gist.githubusercontent.com/miry/3db93ae3f76cb56c3689a2bf355ff1ee/raw/pre-commit" > .git/hooks/pre-commit
chmod +x .git/hooks/post-merge
chmod +x .git/hooks/pre-commit
#!/bin/bash
echo "Removing merged branches..."
git branch --merged master | grep -v "\*" | grep -v master | xargs -n 1 git branch -d
#!/bin/sh
set -e
set -x
for i in $(git diff --name-only | grep -v partials | grep -e 'images/.*\.json')
do
packer validate $i
done
for i in $(git diff --name-only | grep -e '.*\.tf')
do
terraform fmt $i
done
current_dir=$(PWD)
for i in $(git diff --name-only | grep -e '.*\.tf' | grep -v '^modules/')
do
cd $(dirname $i)
terraform validate .
cd $current_dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment