diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 408e43c2a4e4897d562ea90ee0771f849fdcba87..672c02d34208c5ec8268774bb23ed2ca9b530194 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -219,6 +219,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 # ================ @@ -284,8 +288,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 } @@ -359,11 +362,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