-
-
Notifications
You must be signed in to change notification settings - Fork 541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for set env vars inside hook runtime #408
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ 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 | ||
# for all 3rd-party tools executed by a hook. | ||
# FILES (array) filenames to check | ||
# Arguments: | ||
# $@ (array) all specified in `hooks.[].args` in | ||
|
@@ -37,9 +39,11 @@ function common::parse_cmdline { | |
ARGS=() HOOK_CONFIG=() FILES=() | ||
# Used inside `common::terraform_init` function | ||
TF_INIT_ARGS=() | ||
# Used inside `common::export_provided_env_vars` function | ||
ENVS=() | ||
|
||
local argv | ||
argv=$(getopt -o a:,h:,i: --long args:,hook-config:,init-args:,tf-init-args: -- "$@") || return | ||
argv=$(getopt -o a:,h:,i:,e: --long args:,hook-config:,init-args:,tf-init-args:,envs: -- "$@") || return | ||
eval "set -- $argv" | ||
|
||
for argv; do | ||
|
@@ -60,6 +64,11 @@ function common::parse_cmdline { | |
TF_INIT_ARGS+=("$1") | ||
shift | ||
;; | ||
-e | --envs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @antonbabenko Any ideas on how it can be better named? Main idea:
Config example for now - id: terraform_validate
args:
- --envs=AWS_DEFAULT_REGION="us-west-2"
- --envs=AWS_ACCESS_KEY_ID="anaccesskey"
- --envs=AWS_SECRET_ACCESS_KEY="asecretkey" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @yermulnik proposed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. env-vars sounds perfect to me |
||
shift | ||
ENVS+=("$1") | ||
shift | ||
;; | ||
--) | ||
shift | ||
# shellcheck disable=SC2034 # Variable is used | ||
|
@@ -270,3 +279,24 @@ function common::terraform_init { | |
|
||
return $exit_code | ||
} | ||
|
||
####################################################################### | ||
# Export provided K/V as environment variables. | ||
# Arguments: | ||
# env_vars (array) environment variables will be available | ||
# for all 3rd-party tools executed by a hook. | ||
####################################################################### | ||
function common::export_provided_env_vars { | ||
local -a -r env_vars=("$@") | ||
|
||
local var | ||
local var_name | ||
local var_value | ||
|
||
for var in "${env_vars[@]}"; do | ||
var_name="${var%%=*}" | ||
var_value="${var#*=}" | ||
# shellcheck disable=SC2086 | ||
export $var_name="$var_value" | ||
done | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed privately we'll get back to reconsidering this option's name later (e.g. to
--env-vars
or something like that)