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 support for passing args and environment vars to terraform_validate #114

Closed
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
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,51 @@ if they are present in `README.md`.
```yaml
hooks:
- id: terraform_tflint
args: ['args=--deep']
args: ['--args=--deep']
```

In order to pass multiple args, try the following:
```yaml
- id: terraform_tflint
args:
- 'args=--deep'
- 'args=--enable-rule=terraform_documented_variables'
- '--args=--deep'
- '--args=--enable-rule=terraform_documented_variables'
```

## Notes about terraform_validate hooks

1. `terraform_validate` supports custom arguments so you can pass supported no-color or json flags.

1. Example:
```yaml
hooks:
- id: terraform_validate
args: ['--args=-json']
```

In order to pass multiple args, try the following:
```yaml
- id: terraform_validate
args:
- '--args=-json'
- '--args=-no-color'
```
1. `terraform_validate` also supports custom environment variables passed to the pre-commit runtime

1. Example:
```yaml
hooks:
- id: terraform_validate
args: ['--envs=AWS_DEFAULT_REGION="us-west-2"']
```

In order to pass multiple args, try the following:
```yaml
- id: terraform_validate
args:
- '--envs=AWS_DEFAULT_REGION="us-west-2"'
- '--envs=AWS_ACCESS_KEY_ID="anaccesskey"'
- '--envs=AWS_SECRET_ACCESS_KEY="asecretkey"'
```

## Notes about terraform_tfsec hooks
Expand Down
6 changes: 3 additions & 3 deletions terraform_tflint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ main() {
argv=$(getopt -o a: --long args: -- "$@") || return
eval "set -- $argv"

declare args
declare -a args
declare files

for argv; do
case $argv in
-a | --args)
shift
args="$1"
args+=("$1")
shift
;;
--)
Expand All @@ -40,7 +40,7 @@ tflint_() {
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
tflint $args
tflint ${args[@]}
popd > /dev/null
done
}
Expand Down
Loading