From cf07b5ea3ff76d82f9352aad6dc37e43aa769f9d Mon Sep 17 00:00:00 2001 From: Anton Babenko Date: Tue, 22 Sep 2020 14:20:27 +0200 Subject: [PATCH] feat: Add possibility to share tflint config file for subdirs (#149) --- README.md | 10 ++++++++++ terraform_tflint.sh | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53d14b9..c54a5ec 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,16 @@ if they are present in `README.md`. - '--args=--enable-rule=terraform_documented_variables' ``` +1. When you have multiple directories and want to run `tflint` in all of them and share single config file it is impractical to hard-code the path to `.tflint.hcl` file. The solution is to use `__GIT_WORKING_DIR__` placeholder which will be replaced by `terraform_tflint` hooks with Git working directory (repo root) at run time. For example: + + ```yaml + hooks: + - id: terraform_tflint + args: + - '--args=--config=__GIT_WORKING_DIR__/.tflint.hcl' + ``` + + ## Notes about terraform_tfsec hooks 1. `terraform_tfsec` will consume modified files that pre-commit diff --git a/terraform_tflint.sh b/terraform_tflint.sh index e7a212b..670e860 100755 --- a/terraform_tflint.sh +++ b/terraform_tflint.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -eo pipefail main() { initialize_ @@ -35,7 +35,8 @@ parse_cmdline_() { case $argv in -a | --args) shift - ARGS+=("$1") + expanded_arg="${1//__GIT_WORKING_DIR__/$PWD}" + ARGS+=("$expanded_arg") shift ;; --) @@ -45,6 +46,7 @@ parse_cmdline_() { ;; esac done + } tflint_() {