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

Rename `TF_GITLAB_SOURCED` variable to `GITLAB_TOFU_SOURCED`.

This change set renames the `TF_GITLAB_SOURCED` environment variable to
`GITLAB_TOFU_SOURCED` and document the existence of the variable
accordingly in the README.
The reason for renaming it is that the `TF_` variable prefix is "owned"
by OpenTofu / Terraform and not GitLab Tofu. Therefore, we make an
effort to rename these variables to have the `GITLAB_TOFU_` prefix
instead.

Changelog: changed
parent 543cda32
No related branches found
No related tags found
No related merge requests found
...@@ -300,6 +300,9 @@ and will try to execute a `tofu` command. ...@@ -300,6 +300,9 @@ and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`. to `true` before sourcing `gitlab-tofu`.
When the `gitlab-tofu` script is sourced it'll set the `GITLAB_TOFU_SOURCED`
variable to `true`. This variable is not exported by the script itself.
### Best Practices ### Best Practices
This section is a collection of *some* best practices. This section is a collection of *some* best practices.
......
...@@ -315,6 +315,9 @@ and will try to execute a `tofu` command. ...@@ -315,6 +315,9 @@ and will try to execute a `tofu` command.
In this case you can set the `GITLAB_TOFU_SOURCE` environment variable In this case you can set the `GITLAB_TOFU_SOURCE` environment variable
to `true` before sourcing `gitlab-tofu`. to `true` before sourcing `gitlab-tofu`.
When the `gitlab-tofu` script is sourced it'll set the `GITLAB_TOFU_SOURCED`
variable to `true`. This variable is not exported by the script itself.
### Best Practices ### Best Practices
This section is a collection of *some* best practices. This section is a collection of *some* best practices.
......
...@@ -18,6 +18,7 @@ fi ...@@ -18,6 +18,7 @@ fi
# Evaluate if this script is being sourced or executed directly. # Evaluate if this script is being sourced or executed directly.
# See https://stackoverflow.com/a/28776166 # See https://stackoverflow.com/a/28776166
sourced=0 sourced=0
# shellcheck disable=SC2153 # it's actually a different variable, thanks shelllcheck.
if [ "$GITLAB_TOFU_SOURCE" = 'true' ]; then if [ "$GITLAB_TOFU_SOURCE" = 'true' ]; then
sourced=1 sourced=1
elif [ -n "$ZSH_VERSION" ]; then elif [ -n "$ZSH_VERSION" ]; then
...@@ -276,5 +277,5 @@ if [ $sourced -eq 0 ]; then ...@@ -276,5 +277,5 @@ if [ $sourced -eq 0 ]; then
else else
# This variable can be used if the script is sourced # This variable can be used if the script is sourced
# shellcheck disable=SC2034 # shellcheck disable=SC2034
TF_GITLAB_SOURCED=true GITLAB_TOFU_SOURCED=true
fi fi
...@@ -151,9 +151,9 @@ EOF ...@@ -151,9 +151,9 @@ EOF
cat <<'EOF' > test.sh cat <<'EOF' > test.sh
set -x set -x
test -z "$TF_GITLAB_SOURCED" test -z "$GITLAB_TOFU_SOURCED"
. $(which gitlab-tofu) . $(which gitlab-tofu)
test "$TF_GITLAB_SOURCED" test "$GITLAB_TOFU_SOURCED"
EOF EOF
$SHELL test.sh $SHELL test.sh
...@@ -165,9 +165,9 @@ EOF ...@@ -165,9 +165,9 @@ EOF
cat <<'EOF' > test.sh cat <<'EOF' > test.sh
set -x set -x
test -z "$TF_GITLAB_SOURCED" test -z "$GITLAB_TOFU_SOURCED"
. $(which gitlab-tofu) . $(which gitlab-tofu)
test "$TF_GITLAB_SOURCED" test "$GITLAB_TOFU_SOURCED"
EOF EOF
mkdir -p /usr/local/sbin mkdir -p /usr/local/sbin
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment