From 2b35cad50fd7fe1c662cab1bfaab2a4ef7baa3c9 Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Wed, 6 Jul 2022 15:41:28 +0300 Subject: [PATCH] fix: Add `--env-vars`, deprecate `--envs` (#410) --- README.md | 6 +++--- hooks/_common.sh | 12 +++++++----- hooks/infracost_breakdown.sh | 2 +- hooks/terraform_checkov.sh | 2 +- hooks/terraform_docs.sh | 2 +- hooks/terraform_fmt.sh | 2 +- hooks/terraform_providers_lock.sh | 2 +- hooks/terraform_tflint.sh | 2 +- hooks/terraform_tfsec.sh | 2 +- hooks/terraform_validate.sh | 4 ++-- hooks/terraform_wrapper_module_for_each.sh | 2 +- hooks/terragrunt_fmt.sh | 2 +- hooks/terragrunt_validate.sh | 2 +- hooks/terrascan.sh | 2 +- hooks/tfupdate.sh | 2 +- 15 files changed, 24 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 88287ee2e..f799d6ba4 100644 --- a/README.md +++ b/README.md @@ -296,9 +296,9 @@ Config example: ```yaml - id: terraform_validate args: - - --envs=AWS_DEFAULT_REGION="us-west-2" - - --envs=AWS_ACCESS_KEY_ID="anaccesskey" - - --envs=AWS_SECRET_ACCESS_KEY="asecretkey" + - --env-vars=AWS_DEFAULT_REGION="us-west-2" + - --env-vars=AWS_ACCESS_KEY_ID="anaccesskey" + - --env-vars=AWS_SECRET_ACCESS_KEY="asecretkey" ``` ### All hooks: Disable color output diff --git a/hooks/_common.sh b/hooks/_common.sh index b7dba192b..386f3ae07 100644 --- a/hooks/_common.sh +++ b/hooks/_common.sh @@ -26,7 +26,7 @@ function common::initialize { # ARGS (array) arguments that configure wrapped tool behavior # HOOK_CONFIG (array) arguments that configure hook behavior # TF_INIT_ARGS (array) arguments for `terraform init` command -# ENVS (array) environment variables will be available +# ENV_VARS (array) environment variables will be available # for all 3rd-party tools executed by a hook. # FILES (array) filenames to check # Arguments: @@ -40,10 +40,11 @@ function common::parse_cmdline { # Used inside `common::terraform_init` function TF_INIT_ARGS=() # Used inside `common::export_provided_env_vars` function - ENVS=() + ENV_VARS=() local argv - argv=$(getopt -o a:,h:,i:,e: --long args:,hook-config:,init-args:,tf-init-args:,envs: -- "$@") || return + # TODO: Planned breaking change: remove `init-args`, `envs` as not self-descriptive + argv=$(getopt -o a:,h:,i:,e: --long args:,hook-config:,init-args:,tf-init-args:,envs:,env-vars: -- "$@") || return eval "set -- $argv" for argv; do @@ -64,9 +65,10 @@ function common::parse_cmdline { TF_INIT_ARGS+=("$1") shift ;; - -e | --envs) + # TODO: Planned breaking change: remove `--envs` as not self-descriptive + -e | --envs | --env-vars) shift - ENVS+=("$1") + ENV_VARS+=("$1") shift ;; --) diff --git a/hooks/infracost_breakdown.sh b/hooks/infracost_breakdown.sh index 2f3812338..551579112 100755 --- a/hooks/infracost_breakdown.sh +++ b/hooks/infracost_breakdown.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # shellcheck disable=SC2153 # False positive infracost_breakdown_ "${HOOK_CONFIG[*]}" "${ARGS[*]}" diff --git a/hooks/terraform_checkov.sh b/hooks/terraform_checkov.sh index bd37f9778..f64a2644b 100755 --- a/hooks/terraform_checkov.sh +++ b/hooks/terraform_checkov.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Support for setting PATH to repo root. # shellcheck disable=SC2178 # It's the simplest syntax for that case diff --git a/hooks/terraform_docs.sh b/hooks/terraform_docs.sh index fb4d44176..eef887f91 100755 --- a/hooks/terraform_docs.sh +++ b/hooks/terraform_docs.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Support for setting relative PATH to .terraform-docs.yml config. # shellcheck disable=SC2178 # It's the simplest syntax for that case diff --git a/hooks/terraform_fmt.sh b/hooks/terraform_fmt.sh index 637bd9e14..1011357dc 100755 --- a/hooks/terraform_fmt.sh +++ b/hooks/terraform_fmt.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Suppress terraform fmt color diff --git a/hooks/terraform_providers_lock.sh b/hooks/terraform_providers_lock.sh index 5b84ba30d..3036cae23 100755 --- a/hooks/terraform_providers_lock.sh +++ b/hooks/terraform_providers_lock.sh @@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: suppress color for `terraform providers lock` is N/A` diff --git a/hooks/terraform_tflint.sh b/hooks/terraform_tflint.sh index 192786ee9..ae53ce1a2 100755 --- a/hooks/terraform_tflint.sh +++ b/hooks/terraform_tflint.sh @@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Support for setting PATH to repo root. # shellcheck disable=SC2178 # It's the simplest syntax for that case diff --git a/hooks/terraform_tfsec.sh b/hooks/terraform_tfsec.sh index 6538dc7b5..8864b8085 100755 --- a/hooks/terraform_tfsec.sh +++ b/hooks/terraform_tfsec.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Support for setting PATH to repo root. # shellcheck disable=SC2178 # It's the simplest syntax for that case diff --git a/hooks/terraform_validate.sh b/hooks/terraform_validate.sh index 6a3e41ad0..f99f32bcc 100755 --- a/hooks/terraform_validate.sh +++ b/hooks/terraform_validate.sh @@ -13,7 +13,7 @@ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1} function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # Suppress terraform validate color @@ -34,7 +34,7 @@ function main { # args (string with array) arguments that configure wrapped tool behavior # dir_path (string) PATH to dir relative to git repo root. # Can be used in error logging -# ENVS (array) environment variables that will be used with +# ENV_VARS (array) environment variables that will be used with # `terraform` commands # Outputs: # If failed - print out hook checks status diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index 1fd45c30b..dd80b6021 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: suppress color for `hcledit` is N/A` diff --git a/hooks/terragrunt_fmt.sh b/hooks/terragrunt_fmt.sh index 52ded2653..18c9cd673 100755 --- a/hooks/terragrunt_fmt.sh +++ b/hooks/terragrunt_fmt.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: terragrunt hclfmt color already suppressed via PRE_COMMIT_COLOR=never diff --git a/hooks/terragrunt_validate.sh b/hooks/terragrunt_validate.sh index 552dce842..1588450ed 100755 --- a/hooks/terragrunt_validate.sh +++ b/hooks/terragrunt_validate.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never diff --git a/hooks/terrascan.sh b/hooks/terrascan.sh index 63ab66dfd..d36095216 100755 --- a/hooks/terrascan.sh +++ b/hooks/terrascan.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: terrascan color already suppressed via PRE_COMMIT_COLOR=never diff --git a/hooks/tfupdate.sh b/hooks/tfupdate.sh index 080d2e05e..db3fc5b4e 100755 --- a/hooks/tfupdate.sh +++ b/hooks/tfupdate.sh @@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" function main { common::initialize "$SCRIPT_DIR" common::parse_cmdline "$@" - common::export_provided_env_vars "${ENVS[@]}" + common::export_provided_env_vars "${ENV_VARS[@]}" common::parse_and_export_env_vars # JFYI: suppress color for `tfupdate` is N/A`