mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
fix: Add --env-vars, deprecate --envs (#410)
This commit is contained in:
parent
b12f0c662c
commit
2b35cad50f
15 changed files with 24 additions and 22 deletions
|
|
@ -296,9 +296,9 @@ Config example:
|
||||||
```yaml
|
```yaml
|
||||||
- id: terraform_validate
|
- id: terraform_validate
|
||||||
args:
|
args:
|
||||||
- --envs=AWS_DEFAULT_REGION="us-west-2"
|
- --env-vars=AWS_DEFAULT_REGION="us-west-2"
|
||||||
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
|
- --env-vars=AWS_ACCESS_KEY_ID="anaccesskey"
|
||||||
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey"
|
- --env-vars=AWS_SECRET_ACCESS_KEY="asecretkey"
|
||||||
```
|
```
|
||||||
|
|
||||||
### All hooks: Disable color output
|
### All hooks: Disable color output
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ function common::initialize {
|
||||||
# ARGS (array) arguments that configure wrapped tool behavior
|
# ARGS (array) arguments that configure wrapped tool behavior
|
||||||
# HOOK_CONFIG (array) arguments that configure hook behavior
|
# HOOK_CONFIG (array) arguments that configure hook behavior
|
||||||
# TF_INIT_ARGS (array) arguments for `terraform init` command
|
# 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.
|
# for all 3rd-party tools executed by a hook.
|
||||||
# FILES (array) filenames to check
|
# FILES (array) filenames to check
|
||||||
# Arguments:
|
# Arguments:
|
||||||
|
|
@ -40,10 +40,11 @@ function common::parse_cmdline {
|
||||||
# Used inside `common::terraform_init` function
|
# Used inside `common::terraform_init` function
|
||||||
TF_INIT_ARGS=()
|
TF_INIT_ARGS=()
|
||||||
# Used inside `common::export_provided_env_vars` function
|
# Used inside `common::export_provided_env_vars` function
|
||||||
ENVS=()
|
ENV_VARS=()
|
||||||
|
|
||||||
local argv
|
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"
|
eval "set -- $argv"
|
||||||
|
|
||||||
for argv; do
|
for argv; do
|
||||||
|
|
@ -64,9 +65,10 @@ function common::parse_cmdline {
|
||||||
TF_INIT_ARGS+=("$1")
|
TF_INIT_ARGS+=("$1")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-e | --envs)
|
# TODO: Planned breaking change: remove `--envs` as not self-descriptive
|
||||||
|
-e | --envs | --env-vars)
|
||||||
shift
|
shift
|
||||||
ENVS+=("$1")
|
ENV_VARS+=("$1")
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# shellcheck disable=SC2153 # False positive
|
# shellcheck disable=SC2153 # False positive
|
||||||
infracost_breakdown_ "${HOOK_CONFIG[*]}" "${ARGS[*]}"
|
infracost_breakdown_ "${HOOK_CONFIG[*]}" "${ARGS[*]}"
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# Support for setting PATH to repo root.
|
# Support for setting PATH to repo root.
|
||||||
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# Support for setting relative PATH to .terraform-docs.yml config.
|
# Support for setting relative PATH to .terraform-docs.yml config.
|
||||||
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
|
|
||||||
# Suppress terraform fmt color
|
# Suppress terraform fmt color
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: suppress color for `terraform providers lock` is N/A`
|
# JFYI: suppress color for `terraform providers lock` is N/A`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# Support for setting PATH to repo root.
|
# Support for setting PATH to repo root.
|
||||||
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# Support for setting PATH to repo root.
|
# Support for setting PATH to repo root.
|
||||||
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
# shellcheck disable=SC2178 # It's the simplest syntax for that case
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1}
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
|
|
||||||
# Suppress terraform validate color
|
# Suppress terraform validate color
|
||||||
|
|
@ -34,7 +34,7 @@ function main {
|
||||||
# args (string with array) arguments that configure wrapped tool behavior
|
# args (string with array) arguments that configure wrapped tool behavior
|
||||||
# dir_path (string) PATH to dir relative to git repo root.
|
# dir_path (string) PATH to dir relative to git repo root.
|
||||||
# Can be used in error logging
|
# 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
|
# `terraform` commands
|
||||||
# Outputs:
|
# Outputs:
|
||||||
# If failed - print out hook checks status
|
# If failed - print out hook checks status
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: suppress color for `hcledit` is N/A`
|
# JFYI: suppress color for `hcledit` is N/A`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: terragrunt hclfmt color already suppressed via PRE_COMMIT_COLOR=never
|
# JFYI: terragrunt hclfmt color already suppressed via PRE_COMMIT_COLOR=never
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
|
# JFYI: terragrunt validate color already suppressed via PRE_COMMIT_COLOR=never
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: terrascan color already suppressed via PRE_COMMIT_COLOR=never
|
# JFYI: terrascan color already suppressed via PRE_COMMIT_COLOR=never
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||||
function main {
|
function main {
|
||||||
common::initialize "$SCRIPT_DIR"
|
common::initialize "$SCRIPT_DIR"
|
||||||
common::parse_cmdline "$@"
|
common::parse_cmdline "$@"
|
||||||
common::export_provided_env_vars "${ENVS[@]}"
|
common::export_provided_env_vars "${ENV_VARS[@]}"
|
||||||
common::parse_and_export_env_vars
|
common::parse_and_export_env_vars
|
||||||
# JFYI: suppress color for `tfupdate` is N/A`
|
# JFYI: suppress color for `tfupdate` is N/A`
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue