diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 97903566cd23a8302a3da255ad5d78a6411233d7..7c7826e0865d8214b147d4a49f7ec1a823de66ad 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -15,6 +15,7 @@ # 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` +# GITLAB_TOFU_PLAN_JSON: if set is the full path of the plan json file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.json` # # Respected OpenTofu Environment Variables: # > these are variables that are @@ -134,9 +135,9 @@ 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 -if [ -z "${TF_PLAN_JSON}" ]; then - TF_PLAN_JSON="${default_tf_plan_json:-${GITLAB_TOFU_PLAN_NAME}.json}" +# If GITLAB_TOFU_PLAN_JSON is not set then use either the plan.json file within TF_ROOT if set, or plan.json in CWD +if [ -z "${GITLAB_TOFU_PLAN_JSON}" ]; then + GITLAB_TOFU_PLAN_JSON="${default_tf_plan_json:-${GITLAB_TOFU_PLAN_NAME}.json}" fi # Set variables for the HTTP backend to default to TF_* values @@ -265,7 +266,7 @@ if [ $sourced -eq 0 ]; then 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}" > "${TF_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 @@ -277,7 +278,7 @@ if [ $sourced -eq 0 ]; then exit "$ret" ;; "plan-json") - tofu "${TF_CHDIR_OPT}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${TF_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 diff --git a/templates/apply.yml b/templates/apply.yml index c1daee3b2b62d07b847ab598a68cfcbcd120a1cf..4178f018960dc30ace754a0b403b4c25e38274fe 100644 --- a/templates/apply.yml +++ b/templates/apply.yml @@ -75,7 +75,7 @@ spec: description: 'Whether a plan file should be used.' plan_name: default: '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 plan cache and json files.' var_file: default: '' type: string