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

Rename `TF_PLAN_CACHE` to `GITLAB_TOFU_PLAN_CACHE`

Changelog: changed
parent 999bff88
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@
# GITLAB_TOFU_SOURCE: forces this script in source-mode. Required when source auto-detection fails.
# GITLAB_TOFU_APPLY_NO_PLAN: if set to true, the apply command does not use a plan cache file.
# GITLAB_TOFU_PLAN_NAME: the name of the plan cache and json files. Defaults to `plan`.
# GITLAB_TOFU_PLAN_CACHE: if set is the full path of the plan cache file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.cache`
#
# Respected OpenTofu Environment Variables:
# > these are variables that are
......@@ -128,9 +129,9 @@ if [ -n "${TF_ROOT}" ]; then
fi
# If TF_PLAN_CACHE is not set then use either the plan.cache file within TF_ROOT if set, or plan.cache in CWD
if [ -z "${TF_PLAN_CACHE}" ]; then
TF_PLAN_CACHE="${default_tf_plan_cache:-${GITLAB_TOFU_PLAN_NAME}.cache}"
# If GITLAB_TOFU_PLAN_CACHE is not set then use either the plan.cache file within TF_ROOT if set, or plan.cache in CWD
if [ -z "${GITLAB_TOFU_PLAN_CACHE}" ]; then
GITLAB_TOFU_PLAN_CACHE="${default_tf_plan_cache:-${GITLAB_TOFU_PLAN_NAME}.cache}"
fi
# If TF_PLAN_JSON is not set then use either the plan.json file within TF_ROOT if set, or plan.json in CWD
......@@ -234,7 +235,7 @@ 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 "${TF_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}
......@@ -260,11 +261,11 @@ if [ $sourced -eq 0 ]; then
$TF_IMPLICIT_INIT && terraform_init
# shellcheck disable=SC2086
tofu "${TF_CHDIR_OPT}" "${@}" -input=false -out="${TF_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 "${TF_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${TF_PLAN_JSON}"; then
if ! tofu "${TF_CHDIR_OPT}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${TF_PLAN_JSON}"; then
exit $?
fi
......@@ -276,7 +277,7 @@ if [ $sourced -eq 0 ]; then
exit "$ret"
;;
"plan-json")
tofu "${TF_CHDIR_OPT}" show -json "${TF_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${TF_PLAN_JSON}"
tofu "${TF_CHDIR_OPT}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${TF_PLAN_JSON}"
;;
"validate")
$TF_IMPLICIT_INIT && terraform_init -backend=false
......
......@@ -75,7 +75,7 @@ spec:
description: 'Whether a plan file should be used.'
plan_name:
default: 'destroy-plan'
description: 'The name of the plan file to use. Will be used for TF_PLAN_CACHE and TF_PLAN_JSON.'
description: 'The name of the plan file to use. Will be used for the cache and json file.'
var_file:
default: ''
type: string
......
......@@ -82,9 +82,9 @@ EOF
}
@test "gitlab-tofu plan" {
export TF_PLAN_CACHE="test-plan.cache"
export GITLAB_TOFU_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
if [ ! -f "$TF_ROOT/$TF_PLAN_CACHE" ]; then
if [ ! -f "$TF_ROOT/$GITLAB_TOFU_PLAN_CACHE" ]; then
echo "expected to find a plan.cache file"
exit 1
fi
......@@ -97,13 +97,13 @@ EOF
}
@test "gitlab-tofu apply" {
export TF_PLAN_CACHE="test-plan.cache"
export GITLAB_TOFU_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
gitlab-tofu apply
}
@test "gitlab-tofu destroy" {
export TF_PLAN_CACHE="test-plan.cache"
export GITLAB_TOFU_PLAN_CACHE="test-plan.cache"
gitlab-tofu plan
gitlab-tofu apply
gitlab-tofu destroy
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment