Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add possibility to share tflint config file for subdirs #149

Merged
merged 7 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions terraform_tflint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -eo pipefail

main() {
initialize_
Expand Down Expand Up @@ -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
;;
--)
Expand All @@ -45,6 +46,7 @@ parse_cmdline_() {
;;
esac
done

}

tflint_() {
Expand Down