diff --git a/githooks/pre-commit b/githooks/pre-commit new file mode 100644 index 0000000..85ba242 --- /dev/null +++ b/githooks/pre-commit @@ -0,0 +1,26 @@ +#!/bin/bash + +echo "Start git pre-commit hooks"; + +echo "Start terraform docs"; +for i in `ls -d */`;do + if ! git diff --cached --quiet "${i}" + then + echo "Generating doc file: ${i}"; + terraform-docs markdown table --output-file README.md --output-mode inject "${i}"; + fi +done +echo "End terraform docs"; + +echo "Start terraform fmt"; +for y in $(find . -name '*.tf' -print) + do + if ! git diff --cached --quiet "${y}" + then + echo "Formatting the file: ${y}"; + terraform fmt -write=true "${y}" + fi +done +echo "End terraform fmt"; + +echo "End git pre-commit hooks";