From b7538d3d84d9cb2bfcf184032c15928b4d373f53 Mon Sep 17 00:00:00 2001 From: Timo Furrer <tfurrer@gitlab.com> Date: Thu, 12 Dec 2024 13:43:47 +0100 Subject: [PATCH] Pass var file to init This change set passes the configured var file, if any, to the `tofu init` command when it's executed. Closes https://gitlab.com/components/opentofu/-/issues/96 Changelog: changed --- src/gitlab-tofu.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 4b98d61..ca78b34 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -217,6 +217,10 @@ fi # Misc variables var_file="${GITLAB_TOFU_VAR_FILE}" +var_file_args="" +if [ -n "${var_file}" ]; then + var_file_args="--var-file=${var_file}" +fi # Helper functions # ================ @@ -282,8 +286,7 @@ tofu_init() { fi # shellcheck disable=SC2086 # We want to allow word splitting here for `init_flags` - tofu "${tf_chdir_opt}" init "${@}" -input=false ${tofu_init_reconfigure_flag} ${init_flags} \ - 1>&2 || $should_ignore_init_errors + tofu "${tf_chdir_opt}" init "${@}" -input=false ${tofu_init_reconfigure_flag} ${init_flags} ${var_file_args} 1>&2 || $should_ignore_init_errors } @@ -357,11 +360,6 @@ if [ $sourced -eq 0 ]; then # Authenticate to private registry tofu_authenticate_private_registry - var_file_args="" - if [ -n "${var_file}" ]; then - var_file_args="--var-file=${var_file}" - fi - case "${1}" in "apply") $should_do_implicit_init && tofu_init -- GitLab