Thursday, January 10, 2019

Post commit hook for terraform


source

A commit hook to check that terraform files are created properly:


#!/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
    /usr/local/bin/terraform fmt -check=true $f
  fi
done


Place into:

/usr/share/git-core/templates/hooks/

No comments:

Post a Comment