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

Deprecate `TF_ADDRESS` and introduce `GITLAB_TOFU_STATE_ADDRESS` as replacement

Changelog: changed
parent a6bc5c55
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
# GITLAB_TOFU_IGNORE_INIT_ERRORS: if set to true will ignore errors in the `tofu init` command. # GITLAB_TOFU_IGNORE_INIT_ERRORS: if set to true will ignore errors in the `tofu init` command.
# GITLAB_TOFU_INIT_NO_RECONFIGURE: if set to true will not pass `-reconfigure` to the `tofu init` command. # GITLAB_TOFU_INIT_NO_RECONFIGURE: if set to true will not pass `-reconfigure` to the `tofu init` command.
# GITLAB_TOFU_STATE_NAME: the name of the GitLab-managed Terraform state backend endpoint. # GITLAB_TOFU_STATE_NAME: the name of the GitLab-managed Terraform state backend endpoint.
# GITLAB_TOFU_STATE_ADDRESS: the address of the GitLab-managed Terraform state backend. Defaults to `$CI_API_V4_URL/projects/$CI_PROJECT_ID/terraform/state/$GITLAB_TOFU_STATE_NAME`.
# #
# Respected OpenTofu Environment Variables: # Respected OpenTofu Environment Variables:
# > these are variables that are # > these are variables that are
...@@ -41,6 +42,10 @@ ...@@ -41,6 +42,10 @@
# - used as value for TF_TOKEN_<host> variable. # - used as value for TF_TOKEN_<host> variable.
# CI_PROJECT_DIR: # CI_PROJECT_DIR:
# - used as default value for root directory. # - used as default value for root directory.
# CI_PROJECT_ID:
# - used as default value in constructing the GITLAB_TOFU_STATE_ADDRESS.
# CI_API_V4_URL:
# - used as default value in constructing the GITLAB_TOFU_STATE_ADDRESS.
# set some shell options # set some shell options
set -o errexit set -o errexit
...@@ -110,6 +115,16 @@ if [ -n "$TF_STATE_NAME" ]; then ...@@ -110,6 +115,16 @@ if [ -n "$TF_STATE_NAME" ]; then
fi fi
fi fi
if [ -n "$TF_ADDRESS" ]; then
echo 'WARNING: you have manually set the deprecated TF_ADDRESS environment variable. Please use the GITLAB_TOFU_STATE_ADDRESS environment variable instead. The TF_ADDRESS variable will be removed soon.' >&2
if [ -n "$GITLAB_TOFU_STATE_ADDRESS" ]; then
echo 'WARNING: you have set GITLAB_TOFU_STATE_ADDRESS environment variable in addition to the deprecated TF_ADDRESS. This causes a conflict and GITLAB_TOFU_STATE_ADDRESS will be used exclusively' >&2
else
GITLAB_TOFU_STATE_ADDRESS="$TF_ADDRESS"
fi
fi
JQ_PLAN=' JQ_PLAN='
( (
[.resource_changes[]?.change.actions?] | flatten [.resource_changes[]?.change.actions?] | flatten
...@@ -124,11 +139,11 @@ JQ_PLAN=' ...@@ -124,11 +139,11 @@ JQ_PLAN='
state_backend_username="gitlab-ci-token" state_backend_username="gitlab-ci-token"
state_backend_password="${CI_JOB_TOKEN}" state_backend_password="${CI_JOB_TOKEN}"
# If TF_ADDRESS is unset but GITLAB_TOFU_STATE_NAME is provided, then default to GitLab backend in current project # If GITLAB_TOFU_STATE_ADDRESS is unset but GITLAB_TOFU_STATE_NAME is provided, then default to GitLab backend in current project
if [ -n "${GITLAB_TOFU_STATE_NAME}" ] && [ -z "${TF_ADDRESS}" ]; then if [ -n "${GITLAB_TOFU_STATE_NAME}" ] && [ -z "${GITLAB_TOFU_STATE_ADDRESS}" ]; then
# auto url-encode GITLAB_TOFU_STATE_NAME # auto url-encode GITLAB_TOFU_STATE_NAME
GITLAB_TOFU_STATE_NAME="$(jq -rn --arg x "${GITLAB_TOFU_STATE_NAME}" '$x|@uri')" GITLAB_TOFU_STATE_NAME="$(jq -rn --arg x "${GITLAB_TOFU_STATE_NAME}" '$x|@uri')"
TF_ADDRESS="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${GITLAB_TOFU_STATE_NAME}" GITLAB_TOFU_STATE_ADDRESS="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${GITLAB_TOFU_STATE_NAME}"
fi fi
if [ -z "${GITLAB_TOFU_PLAN_NAME}" ]; then if [ -z "${GITLAB_TOFU_PLAN_NAME}" ]; then
...@@ -161,10 +176,10 @@ if [ -z "${GITLAB_TOFU_PLAN_JSON}" ]; then ...@@ -161,10 +176,10 @@ if [ -z "${GITLAB_TOFU_PLAN_JSON}" ]; then
fi fi
# Set variables for the HTTP backend to default to TF_* values # Set variables for the HTTP backend to default to TF_* values
export TF_HTTP_ADDRESS="${TF_HTTP_ADDRESS:-${TF_ADDRESS}}" export TF_HTTP_ADDRESS="${TF_HTTP_ADDRESS:-${GITLAB_TOFU_STATE_ADDRESS}}"
export TF_HTTP_LOCK_ADDRESS="${TF_HTTP_LOCK_ADDRESS:-${TF_ADDRESS}/lock}" export TF_HTTP_LOCK_ADDRESS="${TF_HTTP_LOCK_ADDRESS:-${GITLAB_TOFU_STATE_ADDRESS}/lock}"
export TF_HTTP_LOCK_METHOD="${TF_HTTP_LOCK_METHOD:-POST}" export TF_HTTP_LOCK_METHOD="${TF_HTTP_LOCK_METHOD:-POST}"
export TF_HTTP_UNLOCK_ADDRESS="${TF_HTTP_UNLOCK_ADDRESS:-${TF_ADDRESS}/lock}" export TF_HTTP_UNLOCK_ADDRESS="${TF_HTTP_UNLOCK_ADDRESS:-${GITLAB_TOFU_STATE_ADDRESS}/lock}"
export TF_HTTP_UNLOCK_METHOD="${TF_HTTP_UNLOCK_METHOD:-DELETE}" export TF_HTTP_UNLOCK_METHOD="${TF_HTTP_UNLOCK_METHOD:-DELETE}"
export TF_HTTP_USERNAME="${TF_HTTP_USERNAME:-${state_backend_username}}" export TF_HTTP_USERNAME="${TF_HTTP_USERNAME:-${state_backend_username}}"
export TF_HTTP_PASSWORD="${TF_HTTP_PASSWORD:-${state_backend_password}}" export TF_HTTP_PASSWORD="${TF_HTTP_PASSWORD:-${state_backend_password}}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment