From 56ebe1d5e5592e6864e8e83036daef96f70cf016 Mon Sep 17 00:00:00 2001 From: devops-mher Date: Fri, 29 Apr 2022 10:12:25 +0400 Subject: [PATCH] add terraform-docs tool --- githooks/pre-commit | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 githooks/pre-commit 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";