Commit f69b484d authored by Alexis Deruelle's avatar Alexis Deruelle Committed by Alexis Deruelle
Browse files

fix: skip workspace selection

when using builin Gitlab http backend as it's not compatible

- unset workspace variables when using Gitlab backend
- add a warning message in that case
- add more hints in the doc
parent abd8775d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -314,7 +314,12 @@ Be aware of the following:

* each of those variables support the value `auto`: in that case, the template will use the dynamic [`$environment_slug` value](#deployment-context-variables) as workspace name,
* if the specified workspace doesn't exist, the template will create it,
* HTTP backend (default) doesn't support Workspaces. [See supported backends here](https://developer.hashicorp.com/terraform/language/state/workspaces#backends-supporting-multiple-workspaces).
* HTTP backend doesn't support Workspaces. [See supported backends here](https://developer.hashicorp.com/terraform/language/state/workspaces#backends-supporting-multiple-workspaces).
* corollary as Gitlab http backend is on by default workspace selection is explicitly bypassed
  unless `gitlab-backend-disabled` / `TF_GITLAB_BACKEND_DISABLED` is set to `true`.
  If kept enabled and if any of the `TF_WORKSPACE` variable is set the template will warn about it.
* if using another (non-Gitlab) http backend nothing will prevent from  trying to use workspaces, in
  that case you'll get a Terraform error `workspaces not supported`.

### Using modules from private registries

+10 −0
Original line number Diff line number Diff line
@@ -699,6 +699,16 @@ stages:
        fail "terraform < 0.13.2 doesn't support environment variables to configure http backend"
      fi

      # Gitlab Terraform state storage uses the http backend and this does not support workspaces.
      # With TBC the Gitlab http backend configuration is scoped by environment.
      # If you require another state-scoping scheme to implement
      # workspace-like storage with the Gitlab backend, you can do so
      # by overriding the TF_HTTP_ADDRESS variable to match your use-case.
      if [[ -n "${ENV_WORKSPACE:-$TF_WORKSPACE}" ]]; then
          log_warn "Using Terraform workspace with Gitlab backend is not supported, unsetting (was '${ENV_WORKSPACE:-$TF_WORKSPACE}') ..."
          unset TF_WORKSPACE ENV_WORKSPACE
      fi

      # If TF_USERNAME is unset then default to GITLAB_USER_LOGIN
      TF_USERNAME="${TF_USERNAME:-${GITLAB_USER_LOGIN}}"