From 8c2226857e61d789f01a02fb96feaaadb7c20d6b Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Tue, 27 Sep 2016 19:47:26 +0200 Subject: [PATCH] Initial commit --- .pre-commit-config.yaml | 8 ++++++++ README.md | 16 ++++++++++++++-- hooks.yaml | 6 ++++++ tffmthook.sh | 3 +++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 hooks.yaml create mode 100755 tffmthook.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..424e545 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +- repo: git://github.com/pre-commit/pre-commit-hooks + sha: v0.4.2 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict + - id: check-merge-conflict diff --git a/README.md b/README.md index 4ad4ec1..e60d053 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# pre-commit-terraform -pre-commit git hook for Terraform +# pre-commit-terraform hooks + +Single [pre-commit](http://pre-commit.com/) hook which runs `terraform fmt` on `*.tf` files. + +An example `.pre-commit-config.yaml`: + +```yaml +- repo: git@github.com:antonbabenko/pre-commit-terraform + sha: HEAD + hooks: + - id: terraform_fmt +``` + +Enjoy the clean code! \ No newline at end of file diff --git a/hooks.yaml b/hooks.yaml new file mode 100644 index 0000000..0eebbde --- /dev/null +++ b/hooks.yaml @@ -0,0 +1,6 @@ +- id: terraform_fmt + name: Terraform fmt + description: Rewrites all Terraform configuration files to a canonical format. + entry: tffmthook.sh + language: script + files: \.tf$ diff --git a/tffmthook.sh b/tffmthook.sh new file mode 100755 index 0000000..98f2192 --- /dev/null +++ b/tffmthook.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +[[ -z $(terraform fmt "$@") ]]