Skip to content
Snippets Groups Projects
Unverified Commit 05299a7c authored by Timo Furrer's avatar Timo Furrer
Browse files

Rename internal `TF_CHDIR_OPT` variable

parent 3ce2b643
Branches
Tags
No related merge requests found
......@@ -33,6 +33,8 @@
# CI_JOB_TOKEN:
# - used as default value for TF_HTTP_PASSWORD.
# - used as value for TF_TOKEN_<host> variable.
# CI_PROJECT_DIR:
# - used as default value for root directory.
# set some shell options
set -o errexit
......@@ -123,7 +125,7 @@ fi
if [ -n "${TF_ROOT}" ]; then
abs_tf_root=$(cd "${CI_PROJECT_DIR}"; realpath "${TF_ROOT}")
TF_CHDIR_OPT="-chdir=${abs_tf_root}"
tf_chdir_opt="-chdir=${abs_tf_root}"
default_tf_plan_cache="${abs_tf_root}/${GITLAB_TOFU_PLAN_NAME}.cache"
default_tf_plan_json="${abs_tf_root}/${GITLAB_TOFU_PLAN_NAME}.json"
......@@ -216,7 +218,7 @@ terraform_init() {
# We want to allow word splitting here for TF_INIT_FLAGS
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${TF_INIT_FLAGS} \
tofu "${tf_chdir_opt}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${TF_INIT_FLAGS} \
1>&2 || $TF_IGNORE_INIT_ERRORS
}
......@@ -236,18 +238,18 @@ if [ $sourced -eq 0 ]; then
"apply")
$TF_IMPLICIT_INIT && terraform_init
if [ "$GITLAB_TOFU_APPLY_NO_PLAN" = false ]; then
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -auto-approve "${GITLAB_TOFU_PLAN_CACHE}"
tofu "${tf_chdir_opt}" "${@}" -input=false -auto-approve "${GITLAB_TOFU_PLAN_CACHE}"
else
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -auto-approve ${var_file_args}
tofu "${tf_chdir_opt}" "${@}" -input=false -auto-approve ${var_file_args}
fi
;;
"destroy")
$TF_IMPLICIT_INIT && terraform_init
tofu "${TF_CHDIR_OPT}" "${@}" -auto-approve
tofu "${tf_chdir_opt}" "${@}" -auto-approve
;;
"fmt")
tofu "${TF_CHDIR_OPT}" "${@}" -check -diff -recursive
tofu "${tf_chdir_opt}" "${@}" -check -diff -recursive
;;
"init")
# shift argument list „one to the left“ to not call 'terraform init init'
......@@ -262,11 +264,11 @@ if [ $sourced -eq 0 ]; then
$TF_IMPLICIT_INIT && terraform_init
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -out="${GITLAB_TOFU_PLAN_CACHE}" ${var_file_args} ${plan_args} && ret=$? || ret=$?
tofu "${tf_chdir_opt}" "${@}" -input=false -out="${GITLAB_TOFU_PLAN_CACHE}" ${var_file_args} ${plan_args} && ret=$? || ret=$?
if [ "${GITLAB_TOFU_PLAN_WITH_JSON}" = 'true' ]; then
if [ "$ret" -eq 0 ] || [ "$ret" -eq 2 ]; then
if ! tofu "${TF_CHDIR_OPT}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}"; then
if ! tofu "${tf_chdir_opt}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}"; then
exit $?
fi
......@@ -278,29 +280,29 @@ if [ $sourced -eq 0 ]; then
exit "$ret"
;;
"plan-json")
tofu "${TF_CHDIR_OPT}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}"
tofu "${tf_chdir_opt}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}"
;;
"validate")
$TF_IMPLICIT_INIT && terraform_init -backend=false
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;;
"test")
$TF_IMPLICIT_INIT && terraform_init -backend=false
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;;
"graph")
$TF_IMPLICIT_INIT && terraform_init
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" ${var_file_args}
tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;;
--)
shift
tofu "${TF_CHDIR_OPT}" "${@}"
tofu "${tf_chdir_opt}" "${@}"
;;
*)
tofu "${TF_CHDIR_OPT}" "${@}"
tofu "${tf_chdir_opt}" "${@}"
;;
esac
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment