Skip to content

Commit c4ef91e

Browse files
authored
feat(terrascan): Add support for __GIT_WORKING_DIR__ in hooks arguments (#943)
1 parent 546eb94 commit c4ef91e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,14 @@ If the generated name is incorrect, set them by providing the `module-repo-short
11231123

11241124
See the `terrascan run -h` command line help for available options.
11251125

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:
1127+
1128+
```yaml
1129+
- id: terrascan
1130+
args:
1131+
- --args=--config-path=__GIT_WORKING_DIR__/.terrascan.toml
1132+
```
1133+
11261134
2. Use the `--args=--verbose` parameter to see the rule ID in the scanning output. Useful to skip validations.
11271135
3. Use `--skip-rules="ruleID1,ruleID2"` parameter to skip one or more rules globally while scanning (e.g.: `--args=--skip-rules="ruleID1,ruleID2"`).
11281136
4. Use the syntax `#ts:skip=RuleID optional_comment` inside a resource to skip the rule for that resource.

hooks/terrascan.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function main {
1212
common::parse_cmdline "$@"
1313
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
15+
# Support for setting PATH to repo root.
16+
for i in "${!ARGS[@]}"; do
17+
ARGS[i]=${ARGS[i]/__GIT_WORKING_DIR__/$(pwd)\/}
18+
done
1519
# JFYI: terrascan color already suppressed via PRE_COMMIT_COLOR=never
1620

1721
# shellcheck disable=SC2153 # False positive

0 commit comments

Comments
 (0)