You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add support of __GIT_WORKING_DIR__ placeholder for all hooks (#945)
Move `__GIT_WORKING_DIR__` permutation feature over right into
`common::parse_cmdline` function so that it is available to all hooks
that utilize `common::parse_cmdline` function.
Resolves#944
Copy file name to clipboardExpand all lines: README.md
+44-74Lines changed: 44 additions & 74 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,7 @@ If you want to support the development of `pre-commit-terraform` and [many other
52
52
*[Hooks usage notes and examples](#hooks-usage-notes-and-examples)
53
53
*[Known limitations](#known-limitations)
54
54
*[All hooks: Usage of environment variables in `--args`](#all-hooks-usage-of-environment-variables-in---args)
55
+
*[All hooks: Usage of `__GIT_WORKING_DIR__` placeholder in `--args`](#all-hooks-usage-of-__git_working_dir__-placeholder-in---args)
55
56
*[All hooks: Set env vars inside hook at runtime](#all-hooks-set-env-vars-inside-hook-at-runtime)
56
57
*[All hooks: Disable color output](#all-hooks-disable-color-output)
57
58
*[All hooks: Log levels](#all-hooks-log-levels)
@@ -366,6 +367,24 @@ Config example:
366
367
367
368
If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` before `pre-commit run`, args will be expanded to `--config=.tflint.hcl --call-module-type="all"`.
368
369
370
+
### All hooks: Usage of `__GIT_WORKING_DIR__` placeholder in `--args`
371
+
372
+
373
+
> All, except deprecated hooks: `checkov`, `terraform_docs_replace`
374
+
375
+
You can use `__GIT_WORKING_DIR__` placeholder in `--args`. It will be replaced
376
+
by the Git working directory (repo root) at run time.
377
+
378
+
For instance, if you have multiple directories and want to run
379
+
`terraform_tflint`in all of them while sharing a single config file — use the
380
+
`__GIT_WORKING_DIR__` placeholder in the file path. For example:
381
+
382
+
```yaml
383
+
- id: terraform_tflint
384
+
args:
385
+
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
386
+
```
387
+
369
388
### All hooks: Set env vars inside hook at runtime
370
389
371
390
> All, except deprecated hooks: `checkov`, `terraform_docs_replace`
@@ -478,34 +497,26 @@ If you don't see code above in your `pre-commit-config.yaml` or logs - you don't
478
497
479
498
Note that `terraform_checkov` runs recursively during `-d .` usage. That means, for example, if you change `.tf` file in repo root, all existing `.tf` files in the repo will be checked.
480
499
481
-
1. You can specify custom arguments. E.g.:
482
-
483
-
```yaml
484
-
- id: terraform_checkov
485
-
args:
486
-
- --args=--quiet
487
-
- --args=--skip-check CKV2_AWS_8
488
-
```
489
-
490
-
Check all available arguments [here](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html).
500
+
You can specify custom arguments. E.g.:
491
501
492
-
For deprecated hook you need to specify each argument separately:
502
+
```yaml
503
+
- id: terraform_checkov
504
+
args:
505
+
- --args=--quiet
506
+
- --args=--skip-check CKV2_AWS_8
507
+
```
493
508
494
-
```yaml
495
-
- id: checkov
496
-
args: [
497
-
"-d", ".",
498
-
"--skip-check", "CKV2_AWS_8",
499
-
]
500
-
```
509
+
Check all available arguments [here](https://www.checkov.io/2.Basics/CLI%20Command%20Reference.html).
501
510
502
-
2. When you have multiple directories and want to run `terraform_checkov` in all of them and share a single config file - use the `__GIT_WORKING_DIR__` placeholder. It will be replaced by `terraform_checkov` hooks with the Git working directory (repo root) at run time. For example:
511
+
For deprecated hook you need to specify each argument separately:
2. When you have multiple directories and want to run `tflint` in all of them and share a single config file, it is impractical to hard-code the path to the `.tflint.hcl` file. The solution is to use the `__GIT_WORKING_DIR__` placeholder which will be replaced by `terraform_tflint` hooks with the Git working directory (repo root) at run time. For example:
838
-
839
-
```yaml
840
-
- id: terraform_tflint
841
-
args:
842
-
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
843
-
```
844
-
845
-
3. By default, pre-commit-terraform performs directory switching into the terraform modules for you. If you want to delegate the directory changing to the binary - this will allow tflint to determine the full paths for error/warning messages, rather than just module relative paths. *Note: this requires `tflint>=0.44.0`.* For example:
848
+
2. By default, pre-commit-terraform performs directory switching into the terraform modules for you. If you want to delegate the directory changing to the binary - this will allow tflint to determine the full paths for error/warning messages, rather than just module relative paths. *Note: this requires `tflint>=0.44.0`.* For example:
846
849
847
850
```yaml
848
851
- id: terraform_tflint
849
852
args:
850
853
- --hook-config=--delegate-chdir
851
854
```
852
855
853
-
854
856
### terraform_tfsec (deprecated)
855
857
856
858
**DEPRECATED**. [tfsec was replaced by trivy](https://github.com/aquasecurity/tfsec/discussions/1994), so please use [`terraform_trivy`](#terraform_trivy).
@@ -894,22 +896,6 @@ To replicate functionality in `terraform_docs` hook:
4. When you have multiple directories and want to run `tfsec` in all of them and share a single config file - use the `__GIT_WORKING_DIR__` placeholder. It will be replaced by `terraform_tfsec` hooks with Git working directory (repo root) at run time. For example:
Otherwise, will be used files that located in sub-folders:
906
-
907
-
```yaml
908
-
- id: terraform_tfsec
909
-
args:
910
-
- --args=--config-file=.tfsec.json
911
-
```
912
-
913
899
### terraform_trivy
914
900
915
901
1. `terraform_trivy` will consume modified files that pre-commit
@@ -951,14 +937,6 @@ To replicate functionality in `terraform_docs` hook:
951
937
- --args=--skip-dirs="**/.terraform"
952
938
```
953
939
954
-
4. When you have multiple directories and want to run `trivy` in all of them and share a single config file - use the `__GIT_WORKING_DIR__` placeholder. It will be replaced by `terraform_trivy` hooks with Git working directory (repo root) at run time. For example:
@@ -1123,14 +1101,6 @@ If the generated name is incorrect, set them by providing the `module-repo-short
1123
1101
1124
1102
See the `terrascan run -h` command line help for available options.
1125
1103
1126
-
To pass the config file path, use the `__GIT_WORKING_DIR__` placeholder. It will be replaced with the Git working directory (repo root) at run time. For example:
0 commit comments