diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 36ddd26ab57afbe1f6a6f3209a1d9c9b681698fa..c553ecc2d9d5d7c3b63a2ae462e01d0055187f5a 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -13,6 +13,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`. # # Respected OpenTofu Environment Variables: # > these are variables that are @@ -108,8 +109,8 @@ if [ -n "${TF_STATE_NAME}" ] && [ -z "${TF_ADDRESS}" ]; then TF_ADDRESS="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}" fi -if [ -z "${TF_PLAN_NAME}" ]; then - TF_PLAN_NAME=plan +if [ -z "${GITLAB_TOFU_PLAN_NAME}" ]; then + GITLAB_TOFU_PLAN_NAME=plan fi if [ -z "${GITLAB_TOFU_APPLY_NO_PLAN}" ]; then @@ -122,19 +123,19 @@ if [ -n "${TF_ROOT}" ]; then TF_CHDIR_OPT="-chdir=${abs_tf_root}" - default_tf_plan_cache="${abs_tf_root}/${TF_PLAN_NAME}.cache" - default_tf_plan_json="${abs_tf_root}/${TF_PLAN_NAME}.json" + default_tf_plan_cache="${abs_tf_root}/${GITLAB_TOFU_PLAN_NAME}.cache" + default_tf_plan_json="${abs_tf_root}/${GITLAB_TOFU_PLAN_NAME}.json" 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:-${TF_PLAN_NAME}.cache}" + TF_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 if [ -z "${TF_PLAN_JSON}" ]; then - TF_PLAN_JSON="${default_tf_plan_json:-${TF_PLAN_NAME}.json}" + TF_PLAN_JSON="${default_tf_plan_json:-${GITLAB_TOFU_PLAN_NAME}.json}" fi # Set variables for the HTTP backend to default to TF_* values diff --git a/templates/apply.yml b/templates/apply.yml index 11d00600320aa63ce230896817b6fa373846660a..c1daee3b2b62d07b847ab598a68cfcbcd120a1cf 100644 --- a/templates/apply.yml +++ b/templates/apply.yml @@ -112,7 +112,7 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_APPLY_NO_PLAN: $[[ inputs.no_plan ]] - TF_PLAN_NAME: $[[ inputs.plan_name ]] + GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' diff --git a/templates/destroy.yml b/templates/destroy.yml index 4a2c46e6a200186ed38d80116fca31173165299d..e69b2d4e02439bb52eb57f7c4f98da00bfcee38c 100644 --- a/templates/destroy.yml +++ b/templates/destroy.yml @@ -112,7 +112,7 @@ spec: TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_APPLY_NO_PLAN: $[[ inputs.no_plan ]] - TF_PLAN_NAME: $[[ inputs.plan_name ]] + GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' diff --git a/templates/plan.yml b/templates/plan.yml index 9c6371ac1697b317d63de6e6524c4cdf9f861873..2c1412c4d5ad0fd83091a9366d501d8ab3f75060 100644 --- a/templates/plan.yml +++ b/templates/plan.yml @@ -157,7 +157,7 @@ spec: __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] - TF_PLAN_NAME: $[[ inputs.plan_name ]] + GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] GITLAB_TOFU_PLAN_WITH_JSON: true GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' image: