Commit ba1e368c authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

doc: document scoped variables support

parent c72e23ad
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -270,7 +270,26 @@ resource "aws_instance" "web_server" {
It may happen that you need to use different configuration variables depending on the environment you are deploying.
For instance separate `GOOGLE_CREDENTIALS` if you're using [Google Provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#full-reference).

For this, you shall use [GitLab scoped variables](https://docs.gitlab.com/ee/ci/environments/index.html#scoping-environments-with-specs).
For this, you shall either use [GitLab scoped variables](https://docs.gitlab.com/ee/ci/environments/index.html#scoping-environments-with-specs) or our [scoped variables syntax](https://orange-opensource.gitlab.io/tbc/doc/usage/#scoped-variables) to limit/override some variables values, using `$CI_ENVIRONMENT_NAME` as the conditional variable.

Example: different [OpenStack provider configuration](https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs#configuration-reference) for production

```yaml
variables:
  # global OpenStack provider configuration
  OS_AUTH_URL: "https://openstack-nonprod.api.domain/v3"
  OS_TENANT_ID: "my-nonprod-tenant"
  OS_TENANT_NAME: "my-project-nonprod"
  OS_INSECURE: "true"
  # OS_USERNAME & OS_PASSWORD are defined as secret GitLab CI variables

  # overridden configuration for production
  scoped__OS_AUTH_URL__if__CI_ENVIRONMENT_NAME__equals__production: "https://openstack-prod.api.domain/v3"
  scoped__OS_TENANT_ID__if__CI_ENVIRONMENT_NAME__equals__production: "my-prod-tenant"
  scoped__OS_TENANT_NAME__if__CI_ENVIRONMENT_NAME__equals__production: "my-project-prod"
  scoped__OS_INSECURE__if__CI_ENVIRONMENT_NAME__equals__production: "false"
  # OS_USERNAME & OS_PASSWORD are overridden as secret GitLab CI variables
```

### Supported job artifacts

+0 −1
Original line number Diff line number Diff line
@@ -466,7 +466,6 @@ stages:
  }

  if [[ -z "$TEMPLATE_CHECK_UPDATE_DISABLED" ]]; then check_for_update terraform "1.0.0"; fi

  unscope_variables
  eval_secrets