Skip to content

Commit ae88ed7

Browse files
authored
feat: Add __GIT_WORKING_DIR__ to terraform_checkov (antonbabenko#399)
1 parent 1be6f02 commit ae88ed7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ For deprecated hook you need to specify each argument separately:
310310
]
311311
```
312312

313+
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 Git working directory (repo root) at run time. For example:
314+
315+
```yaml
316+
- id: terraform_checkov
317+
args:
318+
- --args=--config-file __GIT_WORKING_DIR__/.checkov.yml
319+
```
320+
313321
### infracost_breakdown
314322

315323
`infracost_breakdown` executes `infracost breakdown` command and compare the estimated costs with those specified in the hook-config. `infracost breakdown` parses Terraform HCL code, and calls Infracost Cloud Pricing API (remote version or [self-hosted version](https://www.infracost.io/docs/cloud_pricing_api/self_hosted)).

hooks/terraform_checkov.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ function main {
1414
common::initialize "$SCRIPT_DIR"
1515
common::parse_cmdline "$@"
1616
common::parse_and_export_env_vars
17-
# shellcheck disable=SC2153 # False positive
18-
common::per_dir_hook "${ARGS[*]}" "$HOOK_ID" "${FILES[@]}"
17+
# Support for setting PATH to repo root.
18+
# shellcheck disable=SC2178 # It's the simplest syntax for that case
19+
ARGS=${ARGS[*]/__GIT_WORKING_DIR__/$(pwd)\/}
20+
# shellcheck disable=SC2128 # It's the simplest syntax for that case
21+
common::per_dir_hook "$ARGS" "$HOOK_ID" "${FILES[@]}"
1922
}
2023

2124
#######################################################################

0 commit comments

Comments
 (0)