# 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