Skip to content

Commit

Permalink
fix: Improve README and drop quotes from hook env vars (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
yermulnik authored Mar 25, 2024
1 parent 1bdc82b commit daec682
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,18 @@ If for config above set up `export CONFIG_NAME=.tflint; export CONFIG_EXT=hcl` b

You can specify environment variables that will be passed to the hook at runtime.

> [!IMPORTANT]
> Variable values are exported _verbatim_:
> - No interpolation or expansion are applied
> - The enclosing double quotes are removed if they are provided

Config example:

```yaml
- id: terraform_validate
args:
- --env-vars=AWS_DEFAULT_REGION="us-west-2"
- --env-vars=AWS_ACCESS_KEY_ID="anaccesskey"
- --env-vars=AWS_SECRET_ACCESS_KEY="asecretkey"
- --env-vars=AWS_PROFILE="my-aws-cli-profile"
```

### All hooks: Disable color output
Expand Down
5 changes: 5 additions & 0 deletions hooks/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@ function common::export_provided_env_vars {
for var in "${env_vars[@]}"; do
var_name="${var%%=*}"
var_value="${var#*=}"
# Drop enclosing double quotes
if [[ $var_value =~ ^\" && $var_value =~ \"$ ]]; then
var_value="${var_value#\"}"
var_value="${var_value%\"}"
fi
# shellcheck disable=SC2086
export $var_name="$var_value"
done
Expand Down

0 comments on commit daec682

Please sign in to comment.