Skip to content

Commit 2b35cad

Browse files
MaxymVlasovantonbabenko
authored andcommitted
fix: Add --env-vars, deprecate --envs (antonbabenko#410)
1 parent b12f0c6 commit 2b35cad

15 files changed

+24
-22
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ Config example:
296296
```yaml
297297
- id: terraform_validate
298298
args:
299-
- --envs=AWS_DEFAULT_REGION="us-west-2"
300-
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
301-
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
299+
- --env-vars=AWS_DEFAULT_REGION="us-west-2"
300+
- --env-vars=AWS_ACCESS_KEY_ID="anaccesskey"
301+
- --env-vars=AWS_SECRET_ACCESS_KEY="asecretkey"
302302
```
303303

304304
### All hooks: Disable color output

hooks/_common.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function common::initialize {
2626
# ARGS (array) arguments that configure wrapped tool behavior
2727
# HOOK_CONFIG (array) arguments that configure hook behavior
2828
# TF_INIT_ARGS (array) arguments for `terraform init` command
29-
# ENVS (array) environment variables will be available
29+
# ENV_VARS (array) environment variables will be available
3030
# for all 3rd-party tools executed by a hook.
3131
# FILES (array) filenames to check
3232
# Arguments:
@@ -40,10 +40,11 @@ function common::parse_cmdline {
4040
# Used inside `common::terraform_init` function
4141
TF_INIT_ARGS=()
4242
# Used inside `common::export_provided_env_vars` function
43-
ENVS=()
43+
ENV_VARS=()
4444

4545
local argv
46-
argv=$(getopt -o a:,h:,i:,e: --long args:,hook-config:,init-args:,tf-init-args:,envs: -- "$@") || return
46+
# TODO: Planned breaking change: remove `init-args`, `envs` as not self-descriptive
47+
argv=$(getopt -o a:,h:,i:,e: --long args:,hook-config:,init-args:,tf-init-args:,envs:,env-vars: -- "$@") || return
4748
eval "set -- $argv"
4849

4950
for argv; do
@@ -64,9 +65,10 @@ function common::parse_cmdline {
6465
TF_INIT_ARGS+=("$1")
6566
shift
6667
;;
67-
-e | --envs)
68+
# TODO: Planned breaking change: remove `--envs` as not self-descriptive
69+
-e | --envs | --env-vars)
6870
shift
69-
ENVS+=("$1")
71+
ENV_VARS+=("$1")
7072
shift
7173
;;
7274
--)

hooks/infracost_breakdown.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1010
function main {
1111
common::initialize "$SCRIPT_DIR"
1212
common::parse_cmdline "$@"
13-
common::export_provided_env_vars "${ENVS[@]}"
13+
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
1515
# shellcheck disable=SC2153 # False positive
1616
infracost_breakdown_ "${HOOK_CONFIG[*]}" "${ARGS[*]}"

hooks/terraform_checkov.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1010
function main {
1111
common::initialize "$SCRIPT_DIR"
1212
common::parse_cmdline "$@"
13-
common::export_provided_env_vars "${ENVS[@]}"
13+
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
1515
# Support for setting PATH to repo root.
1616
# shellcheck disable=SC2178 # It's the simplest syntax for that case

hooks/terraform_docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1010
function main {
1111
common::initialize "$SCRIPT_DIR"
1212
common::parse_cmdline "$@"
13-
common::export_provided_env_vars "${ENVS[@]}"
13+
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
1515
# Support for setting relative PATH to .terraform-docs.yml config.
1616
# shellcheck disable=SC2178 # It's the simplest syntax for that case

hooks/terraform_fmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1010
function main {
1111
common::initialize "$SCRIPT_DIR"
1212
common::parse_cmdline "$@"
13-
common::export_provided_env_vars "${ENVS[@]}"
13+
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
1515

1616
# Suppress terraform fmt color

hooks/terraform_providers_lock.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1111
function main {
1212
common::initialize "$SCRIPT_DIR"
1313
common::parse_cmdline "$@"
14-
common::export_provided_env_vars "${ENVS[@]}"
14+
common::export_provided_env_vars "${ENV_VARS[@]}"
1515
common::parse_and_export_env_vars
1616
# JFYI: suppress color for `terraform providers lock` is N/A`
1717

hooks/terraform_tflint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1111
function main {
1212
common::initialize "$SCRIPT_DIR"
1313
common::parse_cmdline "$@"
14-
common::export_provided_env_vars "${ENVS[@]}"
14+
common::export_provided_env_vars "${ENV_VARS[@]}"
1515
common::parse_and_export_env_vars
1616
# Support for setting PATH to repo root.
1717
# shellcheck disable=SC2178 # It's the simplest syntax for that case

hooks/terraform_tfsec.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
1010
function main {
1111
common::initialize "$SCRIPT_DIR"
1212
common::parse_cmdline "$@"
13-
common::export_provided_env_vars "${ENVS[@]}"
13+
common::export_provided_env_vars "${ENV_VARS[@]}"
1414
common::parse_and_export_env_vars
1515
# Support for setting PATH to repo root.
1616
# shellcheck disable=SC2178 # It's the simplest syntax for that case

hooks/terraform_validate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1}
1313
function main {
1414
common::initialize "$SCRIPT_DIR"
1515
common::parse_cmdline "$@"
16-
common::export_provided_env_vars "${ENVS[@]}"
16+
common::export_provided_env_vars "${ENV_VARS[@]}"
1717
common::parse_and_export_env_vars
1818

1919
# Suppress terraform validate color
@@ -34,7 +34,7 @@ function main {
3434
# args (string with array) arguments that configure wrapped tool behavior
3535
# dir_path (string) PATH to dir relative to git repo root.
3636
# Can be used in error logging
37-
# ENVS (array) environment variables that will be used with
37+
# ENV_VARS (array) environment variables that will be used with
3838
# `terraform` commands
3939
# Outputs:
4040
# If failed - print out hook checks status

0 commit comments

Comments
 (0)