diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 0f8b02b5949b2822524cd6149de483a51ccb2d5a..116af65cd265b717f73ff7e06ba6cfdd91e127f1 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -148,6 +148,9 @@ terraform_authenticate_private_registry() { # to calling the wrapper `terraform` commands. TF_IMPLICIT_INIT=${TF_IMPLICIT_INIT:-true} +# Allows users to continue the actual command in case init failed +TF_IGNORE_INIT_ERRORS=${TF_IGNORE_INIT_ERRORS:-false} + terraform_init() { # If TF_INIT_NO_RECONFIGURE is not set to 'true', # a `-reconfigure` flag is added to the `terraform init` command. @@ -157,7 +160,8 @@ terraform_init() { # We want to allow word splitting here for TF_INIT_FLAGS # shellcheck disable=SC2086 - tofu "${TF_CHDIR_OPT}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${TF_INIT_FLAGS} + tofu "${TF_CHDIR_OPT}" init "${@}" -input=false ${tf_init_reconfigure_flag} ${TF_INIT_FLAGS} \ + 1>&2 || $TF_IGNORE_INIT_ERRORS } # If this script is executed and not sourced, a terraform command is ran. diff --git a/templates/validate.yml b/templates/validate.yml index 3be97a19b5f1cb90642eabe6a772bbe0f5b59a9c..02578ed07f408c6eef263b76558078448a7cf228 100644 --- a/templates/validate.yml +++ b/templates/validate.yml @@ -69,6 +69,7 @@ spec: __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" TF_ROOT: $[[ inputs.root_dir ]] TF_STATE_NAME: $[[ inputs.state_name ]] + TF_IGNORE_INIT_ERRORS: 'true' # Tofu can report errors which might be the reason init failed. image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]' script: