From f3815f14b7c110653263f686fcec12a262547573 Mon Sep 17 00:00:00 2001 From: Timo Furrer <tfurrer@gitlab.com> Date: Wed, 13 Nov 2024 15:49:59 +0100 Subject: [PATCH] Deprecate `TF_ROOT` and introduce `GITLAB_TOFU_ROOT_DIR` as replacement Changelog: changed --- .gitlab/README.md.template | 5 +++-- README.md | 5 +++-- src/gitlab-tofu.sh | 20 ++++++++++++++----- templates/apply.yml | 4 ++-- templates/custom-command.yml | 4 ++-- templates/destroy.yml | 4 ++-- templates/fmt.yml | 2 +- templates/graph.yml | 4 ++-- templates/module-release.yml | 4 ++-- templates/plan.yml | 8 ++++---- templates/test.yml | 4 ++-- templates/validate.yml | 4 ++-- .../integration-tests/Defaults.gitlab-ci.yml | 2 +- tests/integration-tests/Destroy.gitlab-ci.yml | 4 ++-- ...pelineTriggerInChildPipeline.gitlab-ci.yml | 2 +- .../JobTemplates.gitlab-ci.yml | 2 +- .../ModuleRelease.gitlab-ci.yml | 2 +- tests/integration-tests/TestJob.gitlab-ci.yml | 2 +- ...estroyTriggerInChildPipeline.gitlab-ci.yml | 4 ++-- tests/integration-tests/VarFile.gitlab-ci.yml | 2 +- .../WarningOnNonEmptyPlan.gitlab-ci.yml | 2 +- tests/integration.gitlab-ci.yml | 2 +- tests/unit/gitlab-tofu.bats | 16 +++++++-------- 23 files changed, 60 insertions(+), 48 deletions(-) diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index 0c0e3f1..fa5d0ff 100644 --- a/.gitlab/README.md.template +++ b/.gitlab/README.md.template @@ -210,8 +210,8 @@ plan: extends: [.opentofu:plan] parallel: matrix: - - TF_ROOT: test/ - - TF_ROOT: prod/ + - GITLAB_TOFU_ROOT_DIR: test/ + - GITLAB_TOFU_ROOT_DIR: prod/ ``` Have a look at the [`full-pipeline`](templates/job-templates.yml) for how it's constructed. @@ -516,6 +516,7 @@ When migrating from the GitLab Terraform CI/CD templates you can use the followi - `deploy` -> `apply` - Migrate the `TF_ROOT` variable to the `root_dir` input. - Although the `TF_ROOT` variable is still used and maybe overwritten after the import on individual jobs. + - Note that this component deprecated the `TF_ROOT` variable and uses `GITLAB_TOFU_ROOT_DIR` instead. - Migrate the `TF_STATE_NAME` variable to the `state_name` input. - Although the `TF_STATE_NAME` variable is still used and maybe overwritten after the import on individual jobs. - Note that this component deprecated the `TF_STATE_NAME` variable and uses `GITLAB_TOFU_STATE_NAME` instead. diff --git a/README.md b/README.md index 50905cb..fd240c6 100644 --- a/README.md +++ b/README.md @@ -212,8 +212,8 @@ plan: extends: [.opentofu:plan] parallel: matrix: - - TF_ROOT: test/ - - TF_ROOT: prod/ + - GITLAB_TOFU_ROOT_DIR: test/ + - GITLAB_TOFU_ROOT_DIR: prod/ ``` Have a look at the [`full-pipeline`](templates/job-templates.yml) for how it's constructed. @@ -531,6 +531,7 @@ When migrating from the GitLab Terraform CI/CD templates you can use the followi - `deploy` -> `apply` - Migrate the `TF_ROOT` variable to the `root_dir` input. - Although the `TF_ROOT` variable is still used and maybe overwritten after the import on individual jobs. + - Note that this component deprecated the `TF_ROOT` variable and uses `GITLAB_TOFU_ROOT_DIR` instead. - Migrate the `TF_STATE_NAME` variable to the `state_name` input. - Although the `TF_STATE_NAME` variable is still used and maybe overwritten after the import on individual jobs. - Note that this component deprecated the `TF_STATE_NAME` variable and uses `GITLAB_TOFU_STATE_NAME` instead. diff --git a/src/gitlab-tofu.sh b/src/gitlab-tofu.sh index 47e4c3b..e05526e 100644 --- a/src/gitlab-tofu.sh +++ b/src/gitlab-tofu.sh @@ -125,6 +125,16 @@ if [ -n "$TF_ADDRESS" ]; then fi fi +if [ -n "$TF_ROOT" ]; then + echo 'WARNING: you have manually set the deprecated TF_ROOT environment variable. Please use the GITLAB_TOFU_ROOT_DIR environment variable instead. The TF_ROOT variable will be removed soon.' >&2 + + if [ -n "$GITLAB_TOFU_ROOT_DIR" ]; then + echo 'WARNING: you have set GITLAB_TOFU_ROOT_DIR environment variable in addition to the deprecated TF_ROOT. This causes a conflict and GITLAB_TOFU_ROOT_DIR will be used exclusively' >&2 + else + GITLAB_TOFU_ROOT_DIR="$TF_ROOT" + fi +fi + jq_plan=' ( [.resource_changes[]?.change.actions?] | flatten @@ -154,9 +164,9 @@ if [ -z "${GITLAB_TOFU_APPLY_NO_PLAN}" ]; then GITLAB_TOFU_APPLY_NO_PLAN=false fi -# If TF_ROOT is set then use the -chdir option -if [ -n "${TF_ROOT}" ]; then - abs_tf_root=$(cd "${CI_PROJECT_DIR}"; realpath "${TF_ROOT}") +# If GITLAB_TOFU_ROOT_DIR is set then use the -chdir option +if [ -n "${GITLAB_TOFU_ROOT_DIR}" ]; then + abs_tf_root=$(cd "${CI_PROJECT_DIR}"; realpath "${GITLAB_TOFU_ROOT_DIR}") tf_chdir_opt="-chdir=${abs_tf_root}" @@ -165,12 +175,12 @@ if [ -n "${TF_ROOT}" ]; then fi -# If GITLAB_TOFU_PLAN_CACHE is not set then use either the plan.cache file within TF_ROOT if set, or plan.cache in CWD +# If GITLAB_TOFU_PLAN_CACHE is not set then use either the plan.cache file within GITLAB_TOFU_ROOT_DIR if set, or plan.cache in CWD if [ -z "${GITLAB_TOFU_PLAN_CACHE}" ]; then GITLAB_TOFU_PLAN_CACHE="${default_tf_plan_cache:-${GITLAB_TOFU_PLAN_NAME}.cache}" fi -# If GITLAB_TOFU_PLAN_JSON is not set then use either the plan.json file within TF_ROOT if set, or plan.json in CWD +# If GITLAB_TOFU_PLAN_JSON is not set then use either the plan.json file within GITLAB_TOFU_ROOT_DIR if set, or plan.json in CWD if [ -z "${GITLAB_TOFU_PLAN_JSON}" ]; then GITLAB_TOFU_PLAN_JSON="${default_tf_plan_json:-${GITLAB_TOFU_PLAN_NAME}.json}" fi diff --git a/templates/apply.yml b/templates/apply.yml index 265f456..f8f6b48 100644 --- a/templates/apply.yml +++ b/templates/apply.yml @@ -105,11 +105,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_APPLY_NO_PLAN: $[[ inputs.no_plan ]] GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] diff --git a/templates/custom-command.yml b/templates/custom-command.yml index 50dcdb5..c0b129b 100644 --- a/templates/custom-command.yml +++ b/templates/custom-command.yml @@ -92,11 +92,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' script: diff --git a/templates/destroy.yml b/templates/destroy.yml index c3feb64..56306cc 100644 --- a/templates/destroy.yml +++ b/templates/destroy.yml @@ -105,11 +105,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_APPLY_NO_PLAN: $[[ inputs.no_plan ]] GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] diff --git a/templates/fmt.yml b/templates/fmt.yml index 5c4a6fe..096ed6c 100644 --- a/templates/fmt.yml +++ b/templates/fmt.yml @@ -98,7 +98,7 @@ spec: variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] image: name: '$[[ inputs.image_registry_base ]]/$[[ inputs.image_name ]]:$[[ inputs.version ]]-opentofu$[[ inputs.opentofu_version ]]-$[[ inputs.base_os ]]$[[ inputs.image_digest ]]' script: diff --git a/templates/graph.yml b/templates/graph.yml index bf8c18a..5b1a7ed 100644 --- a/templates/graph.yml +++ b/templates/graph.yml @@ -99,11 +99,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' image: diff --git a/templates/module-release.yml b/templates/module-release.yml index 49010a6..2b909e8 100644 --- a/templates/module-release.yml +++ b/templates/module-release.yml @@ -37,13 +37,13 @@ spec: image: curlimages/curl:8.8.0 variables: TAR_FILENAME: /tmp/${CI_PROJECT_NAME}-${CI_COMMIT_SHA}.tgz - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] UPLOAD_URL: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/terraform/modules/$[[ inputs.module_name ]]/$[[ inputs.module_system ]]/$[[ inputs.module_version ]]/file script: - >- tar -vczf "$TAR_FILENAME" - -C "$TF_ROOT" + -C "$GITLAB_TOFU_ROOT_DIR" --exclude=./.git --exclude=./.terraform* . diff --git a/templates/plan.yml b/templates/plan.yml index b8e6293..f016c35 100644 --- a/templates/plan.yml +++ b/templates/plan.yml @@ -143,19 +143,19 @@ spec: # See https://docs.gitlab.com/ee/ci/yaml/#artifactsaccess for possible values. access: '$[[ inputs.artifacts_access ]]' paths: - - $TF_ROOT/$[[ inputs.plan_name ]].cache + - $GITLAB_TOFU_ROOT_DIR/$[[ inputs.plan_name ]].cache reports: - terraform: $TF_ROOT/$[[ inputs.plan_name]].json + terraform: $GITLAB_TOFU_ROOT_DIR/$[[ inputs.plan_name]].json rules: $[[ inputs.rules ]] cache: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_PLAN_NAME: $[[ inputs.plan_name ]] GITLAB_TOFU_PLAN_WITH_JSON: true diff --git a/templates/test.yml b/templates/test.yml index dc59764..dac7cbc 100644 --- a/templates/test.yml +++ b/templates/test.yml @@ -102,11 +102,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' image: diff --git a/templates/validate.yml b/templates/validate.yml index 7a5beb7..8ffc7b8 100644 --- a/templates/validate.yml +++ b/templates/validate.yml @@ -98,11 +98,11 @@ spec: key: "$__CACHE_KEY_HACK" policy: $[[ inputs.cache_policy ]] paths: - - $TF_ROOT/.terraform/ + - $GITLAB_TOFU_ROOT_DIR/.terraform/ variables: # FIXME: work around to make slashes work in `cache:key`. see https://gitlab.com/gitlab-org/gitlab/-/issues/439898 __CACHE_KEY_HACK: "$[[ inputs.root_dir ]]" - TF_ROOT: $[[ inputs.root_dir ]] + GITLAB_TOFU_ROOT_DIR: $[[ inputs.root_dir ]] GITLAB_TOFU_STATE_NAME: $[[ inputs.state_name ]] GITLAB_TOFU_IGNORE_INIT_ERRORS: 'true' # Tofu can report errors which might be the reason init failed. GITLAB_TOFU_VAR_FILE: '$[[ inputs.var_file ]]' diff --git a/tests/integration-tests/Defaults.gitlab-ci.yml b/tests/integration-tests/Defaults.gitlab-ci.yml index 2058ed7..7cea12e 100644 --- a/tests/integration-tests/Defaults.gitlab-ci.yml +++ b/tests/integration-tests/Defaults.gitlab-ci.yml @@ -5,7 +5,7 @@ include: version: $CI_COMMIT_SHA base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME # Required to run everything immediately, instead of manually. fmt_rules: [{when: always}] diff --git a/tests/integration-tests/Destroy.gitlab-ci.yml b/tests/integration-tests/Destroy.gitlab-ci.yml index b890b8c..2e124b8 100644 --- a/tests/integration-tests/Destroy.gitlab-ci.yml +++ b/tests/integration-tests/Destroy.gitlab-ci.yml @@ -6,7 +6,7 @@ include: opentofu_version: $OPENTOFU_VERSION as: 'setup:apply' stage: setup - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME no_plan: true # Required to run everything immediately, instead of manually. @@ -17,7 +17,7 @@ include: image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE version: $CI_COMMIT_SHA opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME # Required to run everything immediately, instead of manually. fmt_rules: [{when: always}] diff --git a/tests/integration-tests/FullPipelineTriggerInChildPipeline.gitlab-ci.yml b/tests/integration-tests/FullPipelineTriggerInChildPipeline.gitlab-ci.yml index f38b91d..ee7e62d 100644 --- a/tests/integration-tests/FullPipelineTriggerInChildPipeline.gitlab-ci.yml +++ b/tests/integration-tests/FullPipelineTriggerInChildPipeline.gitlab-ci.yml @@ -5,7 +5,7 @@ include: version: $CI_COMMIT_SHA base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME # Required to run everything immediately, instead of manually. fmt_rules: [{when: always}] diff --git a/tests/integration-tests/JobTemplates.gitlab-ci.yml b/tests/integration-tests/JobTemplates.gitlab-ci.yml index 9a862ff..42d8721 100644 --- a/tests/integration-tests/JobTemplates.gitlab-ci.yml +++ b/tests/integration-tests/JobTemplates.gitlab-ci.yml @@ -4,7 +4,7 @@ include: image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE version: $CI_COMMIT_SHA opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME stages: [validate, build, deploy, cleanup] diff --git a/tests/integration-tests/ModuleRelease.gitlab-ci.yml b/tests/integration-tests/ModuleRelease.gitlab-ci.yml index fd8dc3f..6c80fcc 100644 --- a/tests/integration-tests/ModuleRelease.gitlab-ci.yml +++ b/tests/integration-tests/ModuleRelease.gitlab-ci.yml @@ -5,7 +5,7 @@ variables: include: - component: $CI_SERVER_FQDN/$CI_PROJECT_PATH/module-release@$CI_COMMIT_SHA inputs: - root_dir: $TEST_TF_ROOT/modules/random-pet + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR/modules/random-pet module_system: $MODULE_SYSTEM module_version: $MODULE_VERSION diff --git a/tests/integration-tests/TestJob.gitlab-ci.yml b/tests/integration-tests/TestJob.gitlab-ci.yml index dd1dd67..f909407 100644 --- a/tests/integration-tests/TestJob.gitlab-ci.yml +++ b/tests/integration-tests/TestJob.gitlab-ci.yml @@ -4,7 +4,7 @@ include: image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE version: $CI_COMMIT_SHA opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME # Required to run everything immediately, instead of manually. rules: [{when: always}] diff --git a/tests/integration-tests/ValidatePlanDestroyTriggerInChildPipeline.gitlab-ci.yml b/tests/integration-tests/ValidatePlanDestroyTriggerInChildPipeline.gitlab-ci.yml index 662cf67..dcc9253 100644 --- a/tests/integration-tests/ValidatePlanDestroyTriggerInChildPipeline.gitlab-ci.yml +++ b/tests/integration-tests/ValidatePlanDestroyTriggerInChildPipeline.gitlab-ci.yml @@ -6,7 +6,7 @@ include: opentofu_version: $OPENTOFU_VERSION as: 'setup:apply' stage: setup - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME no_plan: true # Required to run everything immediately, instead of manually. @@ -17,7 +17,7 @@ include: image_registry_base: $GITLAB_OPENTOFU_IMAGE_BASE version: $CI_COMMIT_SHA opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME # Required to run everything immediately, instead of manually. fmt_rules: [{when: always}] diff --git a/tests/integration-tests/VarFile.gitlab-ci.yml b/tests/integration-tests/VarFile.gitlab-ci.yml index 429fe65..dec183d 100644 --- a/tests/integration-tests/VarFile.gitlab-ci.yml +++ b/tests/integration-tests/VarFile.gitlab-ci.yml @@ -5,7 +5,7 @@ include: version: $CI_COMMIT_SHA base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME var_file: varfile.integration-test.tfvars # Required to run everything immediately, instead of manually. diff --git a/tests/integration-tests/WarningOnNonEmptyPlan.gitlab-ci.yml b/tests/integration-tests/WarningOnNonEmptyPlan.gitlab-ci.yml index b7f13fb..1edddd7 100644 --- a/tests/integration-tests/WarningOnNonEmptyPlan.gitlab-ci.yml +++ b/tests/integration-tests/WarningOnNonEmptyPlan.gitlab-ci.yml @@ -5,7 +5,7 @@ include: version: $CI_COMMIT_SHA base_os: $GITLAB_OPENTOFU_BASE_IMAGE_OS opentofu_version: $OPENTOFU_VERSION - root_dir: $TEST_TF_ROOT + root_dir: $TEST_GITLAB_TOFU_ROOT_DIR state_name: $TEST_GITLAB_TOFU_STATE_NAME warning_on_non_empty_plan: true diff --git a/tests/integration.gitlab-ci.yml b/tests/integration.gitlab-ci.yml index 140fa7f..9165372 100644 --- a/tests/integration.gitlab-ci.yml +++ b/tests/integration.gitlab-ci.yml @@ -3,7 +3,7 @@ component: variables: OPENTOFU_VERSION: $LATEST_OPENTOFU_VERSION TEST_GITLAB_TOFU_STATE_NAME: ci-integration-$CI_PIPELINE_IID-$CI_NODE_INDEX - TEST_TF_ROOT: tests/iac + TEST_GITLAB_TOFU_ROOT_DIR: tests/iac trigger: include: tests/integration-tests/$PIPELINE_NAME.gitlab-ci.yml strategy: depend diff --git a/tests/unit/gitlab-tofu.bats b/tests/unit/gitlab-tofu.bats index 0637578..f254e5c 100644 --- a/tests/unit/gitlab-tofu.bats +++ b/tests/unit/gitlab-tofu.bats @@ -16,7 +16,7 @@ setup() { cp -r "$TEST_PROJECT_DIR" "$BATS_TEST_TMPDIR" # Set TF root directory to temporary location - export TF_ROOT="$BATS_TEST_TMPDIR/$(basename "$TEST_PROJECT_DIR")" + export GITLAB_TOFU_ROOT_DIR="$BATS_TEST_TMPDIR/$(basename "$TEST_PROJECT_DIR")" # Set state so that each test has its own export GITLAB_TOFU_STATE_NAME="ci-unit-$CI_JOB_ID-$BATS_SUITE_TEST_NUMBER" @@ -44,16 +44,16 @@ teardown() { gitlab-tofu init -no-color } -@test "gitlab-tofu init within TF_ROOT set" { - cd "$TF_ROOT" - unset "$TF_ROOT" +@test "gitlab-tofu init within GITLAB_TOFU_ROOT_DIR set" { + cd "$GITLAB_TOFU_ROOT_DIR" + unset "$GITLAB_TOFU_ROOT_DIR" gitlab-tofu init -no-color } @test "gitlab-tofu init without reconfigure" { gitlab-tofu init - cat <<EOF > $TF_ROOT/backend_override.tf + cat <<EOF > $GITLAB_TOFU_ROOT_DIR/backend_override.tf terraform { backend "local" {} } @@ -65,7 +65,7 @@ EOF } @test "gitlab-tofu init with reconfigure" { - cat <<EOF > $TF_ROOT/backend_override.tf + cat <<EOF > $GITLAB_TOFU_ROOT_DIR/backend_override.tf terraform { backend "local" {} } @@ -84,13 +84,13 @@ EOF @test "gitlab-tofu plan" { export GITLAB_TOFU_PLAN_CACHE="test-plan.cache" gitlab-tofu plan - if [ ! -f "$TF_ROOT/$GITLAB_TOFU_PLAN_CACHE" ]; then + if [ ! -f "$GITLAB_TOFU_ROOT_DIR/$GITLAB_TOFU_PLAN_CACHE" ]; then echo "expected to find a plan.cache file" exit 1 fi gitlab-tofu plan-json - if [ ! -f "$TF_ROOT/plan.json" ]; then + if [ ! -f "$GITLAB_TOFU_ROOT_DIR/plan.json" ]; then echo "expected to find a plan.json file" exit 1 fi -- GitLab