Skip to content

Commit cf07b5e

Browse files
authored
feat: Add possibility to share tflint config file for subdirs (antonbabenko#149)
1 parent e4ab410 commit cf07b5e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ if they are present in `README.md`.
121121
- '--args=--enable-rule=terraform_documented_variables'
122122
```
123123

124+
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:
125+
126+
```yaml
127+
hooks:
128+
- id: terraform_tflint
129+
args:
130+
- '--args=--config=__GIT_WORKING_DIR__/.tflint.hcl'
131+
```
132+
133+
124134
## Notes about terraform_tfsec hooks
125135

126136
1. `terraform_tfsec` will consume modified files that pre-commit

terraform_tflint.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -eo pipefail
44

55
main() {
66
initialize_
@@ -35,7 +35,8 @@ parse_cmdline_() {
3535
case $argv in
3636
-a | --args)
3737
shift
38-
ARGS+=("$1")
38+
expanded_arg="${1//__GIT_WORKING_DIR__/$PWD}"
39+
ARGS+=("$expanded_arg")
3940
shift
4041
;;
4142
--)
@@ -45,6 +46,7 @@ parse_cmdline_() {
4546
;;
4647
esac
4748
done
49+
4850
}
4951

5052
tflint_() {

0 commit comments

Comments
 (0)