From bd50003bd773511e596c67984c144cc5774dac4c Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Mon, 15 Jan 2018 16:12:51 +0100 Subject: [PATCH] Added formatting for tfvars (fixes #4) (#6) --- .pre-commit-config.yaml | 17 +++++++++-------- .pre-commit-hooks.yaml | 14 +++++++------- README.md | 10 +++++----- hooks.yaml | 14 +++++++------- terraform_fmt.sh | 2 +- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f788ca2..454e4a0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,9 @@ -- repo: git://github.com/pre-commit/pre-commit-hooks - sha: v0.6.0 - hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace - - id: check-case-conflict - - id: check-merge-conflict +repos: +- repo: git://github.com/pre-commit/pre-commit-hooks + sha: v1.2.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-case-conflict + - id: check-merge-conflict diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index eb42d4a..f77a70d 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,7 @@ -- id: terraform_fmt - name: Terraform fmt - description: Rewrites all Terraform configuration files to a canonical format. - entry: terraform_fmt.sh - language: script - files: \.tf$ - exclude: \.+.terraform\/.*$ +- id: terraform_fmt + name: Terraform fmt + description: Rewrites all Terraform configuration files to a canonical format. + entry: terraform_fmt.sh + language: script + files: (\.tf|\.tfvars)$ + exclude: \.terraform\/.*$ diff --git a/README.md b/README.md index 43a9161..4d744df 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,15 @@ [![Help Contribute to Open Source](https://www.codetriage.com/antonbabenko/pre-commit-terraform/badges/users.svg)](https://www.codetriage.com/antonbabenko/pre-commit-terraform) -Single [pre-commit](http://pre-commit.com/) hook which runs `terraform fmt` on `*.tf` files. +Single [pre-commit](http://pre-commit.com/) hook which runs `terraform fmt` on Terraform configuration files (both `*.tf` and `*.tfvars`). An example `.pre-commit-config.yaml`: ```yaml -- repo: git://github.com/antonbabenko/pre-commit-terraform - sha: v1.2.0 - hooks: - - id: terraform_fmt +- repo: git://github.com/antonbabenko/pre-commit-terraform + sha: v1.3.0 + hooks: + - id: terraform_fmt ``` Enjoy the clean code! diff --git a/hooks.yaml b/hooks.yaml index eb42d4a..f77a70d 100644 --- a/hooks.yaml +++ b/hooks.yaml @@ -1,7 +1,7 @@ -- id: terraform_fmt - name: Terraform fmt - description: Rewrites all Terraform configuration files to a canonical format. - entry: terraform_fmt.sh - language: script - files: \.tf$ - exclude: \.+.terraform\/.*$ +- id: terraform_fmt + name: Terraform fmt + description: Rewrites all Terraform configuration files to a canonical format. + entry: terraform_fmt.sh + language: script + files: (\.tf|\.tfvars)$ + exclude: \.terraform\/.*$ diff --git a/terraform_fmt.sh b/terraform_fmt.sh index e1385a6..6c1b693 100755 --- a/terraform_fmt.sh +++ b/terraform_fmt.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash for file in "$@"; do - terraform fmt `dirname $file` + terraform fmt "$file" done