Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created March 10, 2019 21:30
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 felixhummel/bf2026ee1af91fb1662b710c58a68062 to your computer and use it in GitHub Desktop.
Save felixhummel/bf2026ee1af91fb1662b710c58a68062 to your computer and use it in GitHub Desktop.
terraform pre-commit hook to format staged .tf files
#!/bin/bash
# License: WTFPL
set -euo pipefail
# "--diff-filter d" excludes deleted files from this list
files=$(git diff --cached --diff-filter d --name-only -- "*.tf")
for f in $files; do
terraform fmt "$f"
git add "$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment