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

Rename `TF_IMPLICIT_INIT` to `GITLAB_TOFU_IMPLICIT_INIT`

Changelog: changed
parent 05299a7c
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# GITLAB_TOFU_PLAN_NAME: the name of the plan cache and json files. Defaults to `plan`. # 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_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` # GITLAB_TOFU_PLAN_JSON: if set is the full path of the plan json file. Defaults to `<root>/$GITLAB_TOFU_PLAN_NAME.json`
# GITLAB_TOFU_IMPLICIT_INIT: if set to true will perform an implicit tofu init before any command that require it. Defaults to `true`.
# #
# Respected OpenTofu Environment Variables: # Respected OpenTofu Environment Variables:
# > these are variables that are # > these are variables that are
...@@ -201,10 +202,10 @@ terraform_authenticate_private_registry() { ...@@ -201,10 +202,10 @@ terraform_authenticate_private_registry() {
fi fi
} }
# If TF_IMPLICIT_INIT is not set, we set it to `true`. # If GITLAB_TOFU_IMPLICIT_INIT is not set, we set it to `true`.
# If set to `true` it will call `terraform init` prior # If set to `true` it will call `terraform init` prior
# to calling the wrapper `terraform` commands. # to calling the wrapper `terraform` commands.
TF_IMPLICIT_INIT=${TF_IMPLICIT_INIT:-true} GITLAB_TOFU_IMPLICIT_INIT=${GITLAB_TOFU_IMPLICIT_INIT:-true}
# Allows users to continue the actual command in case init failed # Allows users to continue the actual command in case init failed
TF_IGNORE_INIT_ERRORS=${TF_IGNORE_INIT_ERRORS:-false} TF_IGNORE_INIT_ERRORS=${TF_IGNORE_INIT_ERRORS:-false}
...@@ -236,7 +237,7 @@ if [ $sourced -eq 0 ]; then ...@@ -236,7 +237,7 @@ if [ $sourced -eq 0 ]; then
case "${1}" in case "${1}" in
"apply") "apply")
$TF_IMPLICIT_INIT && terraform_init $GITLAB_TOFU_IMPLICIT_INIT && terraform_init
if [ "$GITLAB_TOFU_APPLY_NO_PLAN" = false ]; then if [ "$GITLAB_TOFU_APPLY_NO_PLAN" = false ]; then
tofu "${tf_chdir_opt}" "${@}" -input=false -auto-approve "${GITLAB_TOFU_PLAN_CACHE}" tofu "${tf_chdir_opt}" "${@}" -input=false -auto-approve "${GITLAB_TOFU_PLAN_CACHE}"
else else
...@@ -245,7 +246,7 @@ if [ $sourced -eq 0 ]; then ...@@ -245,7 +246,7 @@ if [ $sourced -eq 0 ]; then
fi fi
;; ;;
"destroy") "destroy")
$TF_IMPLICIT_INIT && terraform_init $GITLAB_TOFU_IMPLICIT_INIT && terraform_init
tofu "${tf_chdir_opt}" "${@}" -auto-approve tofu "${tf_chdir_opt}" "${@}" -auto-approve
;; ;;
"fmt") "fmt")
...@@ -262,7 +263,7 @@ if [ $sourced -eq 0 ]; then ...@@ -262,7 +263,7 @@ if [ $sourced -eq 0 ]; then
plan_args='-detailed-exitcode' plan_args='-detailed-exitcode'
fi fi
$TF_IMPLICIT_INIT && terraform_init $GITLAB_TOFU_IMPLICIT_INIT && terraform_init
# shellcheck disable=SC2086 # shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" -input=false -out="${GITLAB_TOFU_PLAN_CACHE}" ${var_file_args} ${plan_args} && ret=$? || ret=$? tofu "${tf_chdir_opt}" "${@}" -input=false -out="${GITLAB_TOFU_PLAN_CACHE}" ${var_file_args} ${plan_args} && ret=$? || ret=$?
...@@ -283,17 +284,17 @@ if [ $sourced -eq 0 ]; then ...@@ -283,17 +284,17 @@ if [ $sourced -eq 0 ]; then
tofu "${tf_chdir_opt}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}" tofu "${tf_chdir_opt}" show -json "${GITLAB_TOFU_PLAN_CACHE}" | jq -r "${JQ_PLAN}" > "${GITLAB_TOFU_PLAN_JSON}"
;; ;;
"validate") "validate")
$TF_IMPLICIT_INIT && terraform_init -backend=false $GITLAB_TOFU_IMPLICIT_INIT && terraform_init -backend=false
# shellcheck disable=SC2086 # shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" ${var_file_args} tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;; ;;
"test") "test")
$TF_IMPLICIT_INIT && terraform_init -backend=false $GITLAB_TOFU_IMPLICIT_INIT && terraform_init -backend=false
# shellcheck disable=SC2086 # shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" ${var_file_args} tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;; ;;
"graph") "graph")
$TF_IMPLICIT_INIT && terraform_init $GITLAB_TOFU_IMPLICIT_INIT && terraform_init
# shellcheck disable=SC2086 # shellcheck disable=SC2086
tofu "${tf_chdir_opt}" "${@}" ${var_file_args} tofu "${tf_chdir_opt}" "${@}" ${var_file_args}
;; ;;
......
...@@ -110,28 +110,28 @@ EOF ...@@ -110,28 +110,28 @@ EOF
} }
@test "gitlab-tofu validate without implicit init" { @test "gitlab-tofu validate without implicit init" {
export TF_IMPLICIT_INIT=false export GITLAB_TOFU_IMPLICIT_INIT=false
run ! gitlab-tofu validate -no-color run ! gitlab-tofu validate -no-color
assert_output --partial 'This module is not yet installed' assert_output --partial 'This module is not yet installed'
} }
@test "gitlab-tofu plan without implicit init" { @test "gitlab-tofu plan without implicit init" {
export TF_IMPLICIT_INIT=false export GITLAB_TOFU_IMPLICIT_INIT=false
run ! gitlab-tofu plan -no-color run ! gitlab-tofu plan -no-color
assert_output --partial 'Error: Backend initialization required' assert_output --partial 'Error: Backend initialization required'
} }
@test "gitlab-tofu apply without implicit init" { @test "gitlab-tofu apply without implicit init" {
export TF_IMPLICIT_INIT=false export GITLAB_TOFU_IMPLICIT_INIT=false
run ! gitlab-tofu apply -no-color run ! gitlab-tofu apply -no-color
assert_output --partial 'Error: Failed to load ' assert_output --partial 'Error: Failed to load '
} }
@test "gitlab-tofu destroy without implicit init" { @test "gitlab-tofu destroy without implicit init" {
export TF_IMPLICIT_INIT=false export GITLAB_TOFU_IMPLICIT_INIT=false
run ! gitlab-tofu destroy -no-color run ! gitlab-tofu destroy -no-color
assert_output --partial 'Error: Backend initialization required' assert_output --partial 'Error: Backend initialization required'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment