Commit 2af306c3 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'fix/td-address-module-duplicated' into 'main'

fix: remove namespace prefix since environment_slug is already taking it into account

See merge request to-be-continuous/terraform!171
parents ffd0393b 7de47e2a
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -272,8 +272,14 @@ variables:

The above configuration will deploy 2 enviroments on deployments jobs (`tf-plan-*`, `tf-review`, `tf-destroy-*`, etc.).

:info: When using both this feature and [GitLab backend](#gitlab-managed-terraform-state-default), the state name will be `<namespace>_<environment_slug>`
where `namespace` is built from `TF_ENVIRONMENT_NAMESPACE` (stripped of punctuation characters and converted to lowercase).
> [!note]
> When using both this feature and [GitLab backend](#gitlab-managed-terraform-state-default),
> the state name (based on `$CI_ENVIRONMENT_SLUG`) will implicitly contain the environment namespace.
> As examples, with the above namespace, it will respectively be for the various environments:
> - For 'some-project-id': `review-some-proje-k6x51d`, `integration-some-55v14l`, `staging-some-proj-p2bkuw`, `production-some-p-enhwzj`
> - For 'some-other-project-id': `review-some-other-8uad93`, `integration-some-ozug25`, `staging-some-othe-2pelfe`, `production-some-o-og55ux`
>
> If needed, the whole HTTP state URL can be overridden with `TF_ADDRESS` (defaults to `${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${environment_slug}`) environment variable.

### Supported output artifacts

+2 −2
Original line number Diff line number Diff line
@@ -830,8 +830,8 @@ stages:
      fi

      # If TF_ADDRESS is unset then default to GitLab backend in current project
      prefix="${environment_namespace:+${environment_namespace}_}"
      TF_ADDRESS="${TF_ADDRESS:-${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${prefix}${environment_slug}}"
      # environment slug implicitly contains the environment namespace (matrix support)
      TF_ADDRESS="${TF_ADDRESS:-${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${environment_slug}}"

      # Set variables for the HTTP backend to default to TF_* values
      # see: https://developer.hashicorp.com/terraform/language/settings/backends/http