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

feat(workspace): support auto value

parent d94c4b0c
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -267,6 +267,20 @@ the template supports an implicit [backend configuration](https://www.terraform.

If one of those files are found, it is automatically used by the template in the `terraform init` command (using the `-backend-config` CLI option).

#### Workspace management

You may want to make use of [Terraform Workspace](https://www.terraform.io/language/state/workspaces) 
to ease segregating you multiple environments (tfstate management) by setting variables:

* `$TF_WORKSPACE` to set default workspace,
* `$TF_REVIEW_WORKSPACE`, `$TF_INTEG_WORKSPACE`, `$TF_STAGING_WORKSPACE`, `$TF_PROD_WORKSPACE` to override per environment.

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).

## Configuration reference

### Secrets management
+5 −0
Original line number Diff line number Diff line
@@ -424,6 +424,11 @@ stages:
    if [[ -n "$workspace" ]]
    then
      log_info "--- use workspace: \\e[33;1m${workspace}\\e[0m"
      if [[ "$workspace" == "auto" ]]
      then
        workspace="$environment_slug"
        log_info "   ... auto workspace: \\e[33;1m${workspace}\\e[0m"
      fi
      unset TF_WORKSPACE
      terraform workspace select "${workspace}" 2> /dev/null || terraform workspace new "${workspace}"
    fi