diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template index 0c0e3f196833cbc6cf90c9ea567eb0b9d1403216..fa5d0ff996d9c0e3798f1eb9fed0402e41825f6e 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 50905cb7f14823a127cd0b776109d6e3e06557d4..fd240c6ec324d1f1e5723be681314f63933f02ca 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 47e4c3ba13efd3726778af33f8b7ee655f80b7a0..e05526e23c234884d161e64f8e0e2a862cf3ecdb 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 265f4566b0db340b4a8c9e42c244638a94c6f7c3..f8f6b4801b94db63692c76733a084e7930680c7a 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 50dcdb5cab0db1fb94ffaa9677876118d9921294..c0b129b7593b86b64a94efd51097f10f5bd6f2aa 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 c3feb644df203e4ec112dc883279ce0bc2c57f8b..56306cc5bf4f9a72f5a1fadd96861f206f76cf6d 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 5c4a6fe8e711488a438068ea6a1f9afa99973b5b..096ed6c26486c20bace7685c8175f011b534ac7f 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 bf8c18abde4ea1e6cc6a63789bdb5974648daddd..5b1a7ed0636b89405b26672fe2ee163bbc1a52cf 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 49010a6f169e5dd7b4979f9da0e8d67f9a8f407c..2b909e8325c43b0c8808ef5cbcbb7b067b169d31 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 b8e62935f0053bed755e24c519f6be9012a78c9b..f016c3522f9b151f12ce300ead942a2bec960955 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 dc59764d10853c77b7851dac4d0fc7707defc51a..dac7cbcb8e6b7d08c52ae94fec1038942171acff 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 7a5beb7c11d9349d76a944e924df31ff0bd85297..8ffc7b880dd33c37d02fdbaf2a7cd090d96cd9a8 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 2058ed777d67dc29771bc5eb6bc5d8fadf2abbd2..7cea12e3e8e6e93e97cd23223b456a260f491731 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 b890b8c55fe19eb5d5c8e0b1b75856d536b5a6d8..2e124b87852383f3e8448ef71e841cb375b32044 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 f38b91d8237f3cc7ca1c90dde7ce50abd0c1fe39..ee7e62d7dfe5d1e141a2fe0645e66ec2cc186b3b 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 9a862ff7015f1c5215199145f49fe9197befd748..42d872115c88f6583f48be991e71010014229927 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 fd8dc3fac72e1d8ebedde2ffcbd30852c43e0352..6c80fcc0b11ec5a99abc5736516354c4a0b13d91 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 dd1dd67504d0a6005499cc85fc2dd4a5a3c85c70..f9094079328894981620fe32af3c7d7c110c2093 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 662cf67e49398ac0e27fb7b7eb9aec5bcdea2f38..dcc9253f0deed21ae451fdffaa829556b1a5f288 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 429fe655cc397df742e5ee65d0eadb3c3872ae9a..dec183d53e8e26f0d42680099f14b4cf9174ea5e 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 b7f13fb2809c375087845a862ffa8606800b4973..1edddd7d70364a78abb67d8b4381025e72d17b83 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 140fa7f8834d6b59960a45cb287d47ea3535a607..9165372622a0bdd0ae329e2670b0b9baac351726 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 0637578eafde39226954394b0c58e8f19e4d7339..f254e5cfeecf595157ac4417a54c7ef6824f96a9 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