> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/infrastructure-as-code-management/3.0/platform/workspaces/workspace-expressions.md).

# Workspace Expressions

Harness workspace expressions empower you to dynamically reference workspace-level parameters within your pipelines, enhancing flexibility and customization. By leveraging JEXL (Java Expression Language), you can seamlessly access key workspace attributes.

#### Key Benefits <a href="#key-benefits" id="key-benefits"></a>

* **Dynamic Retrieval:** Access workspace-specific identifiers and paths effortlessly.
* **Environment Integration:** Utilize environment and secret variables within the workspace context.
* **Versioning and Provisioning:** Integrate versioning and provisioner details directly into your pipeline logic.
* **Cost Management:** Extract outputs and control cost estimation features.
* **Git Management:** Seamlessly manage Git-related parameters like repository name, branch, commit SHA, and tags.

These expressions are invaluable when adapting pipelines to different environments or configurations.

{% hint style="info" %}
**MIGRATE EXPRESSIONS**

Go to the **Migrate Expressions** tab in the [How to Use Workspace Expressions](#how-to-use-workspace-expressions) section to update old expressions to the latest format.
{% endhint %}

### Available Workspace Expressions <a href="#available-workspace-expressions" id="available-workspace-expressions"></a>

Supported workspace expressions are written in the syntax **`<+workspace.ATTRIBUTE>`**, where ATTRIBUTE can be a single or multi-level identifier, such as:

* **`<+workspace.identifier>`**
* **`<+workspace.type>`** (e.g., opentofu)
* **`<+workspace.envVars.SOME_ENV_VAR>`**

<details>

<summary>See full list of supported workspace expressions</summary>

| **Parameter**                   | **Expression**                         | **Description**                                                                 |
| ------------------------------- | -------------------------------------- | ------------------------------------------------------------------------------- |
| **Workspace ID**                | `<+workspace.identifier>`              | Retrieves the unique identifier for the workspace.                              |
| **Folder Path**                 | `<+workspace.folderPath>`              | Returns the root directory path associated with the workspace.                  |
| **Provisioner Type**            | `<+workspace.type>`                    | Provides the type of provisioner being used, such as `opentofu` or `terraform`. |
| **Provisioner Version**         | `<+workspace.provisionerVersion>`      | Fetches the version of the provisioner used in the workspace.                   |
| **Connector Reference**         | `<+workspace.connectorRef>`            | Retrieves the connector reference associated with the workspace.                |
| **Environment Variable**        | `<+workspace.envVars.SOME_ENV_VAR>`    | Accesses a specific environment variable within the workspace.                  |
| **Terraform/Opentofu Variable** | `<+workspace.variables.OPEN_TOFU_VAR>` | Retrieves a variable specific to Terraform or OpenTofu within the workspace.    |
| **Secret Variable**             | `<+workspace.envVars.SECRET_ENV_VAR>`  | Accesses a secret variable defined in the workspace.                            |
| **Output**                      | `<+workspace.outputs.OUTPUT_ID>`       | Retrieves a specific output from the workspace.                                 |
| **Workspace Name**              | `<+workspace.name>`                    | Returns the name of the workspace.                                              |
| **Cost Estimation Enabled**     | `<+workspace.enableCostEstimation>`    | Indicates whether cost estimation is enabled for the workspace.                 |
| **Git Connector Reference**     | `<+workspace.gitConnectorRef>`         | Retrieves the Git connector reference for the workspace.                        |
| **Git Repository Name**         | `<+workspace.gitRepoName>`             | Provides the name of the Git repository associated with the workspace.          |
| **Git Branch**                  | `<+workspace.gitBranch>`               | Returns the name of the Git branch currently in use.                            |
| **Git SHA**                     | `<+workspace.gitSha>`                  | Retrieves the commit SHA from the Git repository.                               |
| **Git Tag**                     | `<+workspace.gitTag>`                  | Returns the Git tag associated with the current commit.                         |

</details>

### How to Use Workspace Expressions <a href="#how-to-use-workspace-expressions" id="how-to-use-workspace-expressions"></a>

Here's an example of applying workspace expressions in your pipelines to output the workspace identifier and secret variable value.

{% hint style="warning" %}
**RESERVED KEYWORD**

Avoid naming your run step `workspace` as it is a reserved keyword.
{% endhint %}

{% tabs %}
{% tab title="Interactive Guide" %}
{% embed url="<https://app.tango.us/app/embed/2bac0ddc-f01d-4b9e-ac7a-d7776160cfe8>" %}
Using Harness Workspace Expressions
{% endembed %}
{% endtab %}

{% tab title="Migrate Expressions" %}
If you're using an older expression format, update it to the new format as follows:

For example, update secret variables from:

```hcl
// OLD
<+pipeline.stages.stage_name.spec.execution.steps.step_name.spec.secretVariables.secret_variable_name>

// NEW
<+workspace.envVars.SECRET_ENV_VAR>
```

The following guide demonstrates updating your workspace's secret environment variable reference:

{% embed url="<https://app.tango.us/app/embed/ad446a5f-cc13-408c-be77-8d19c241f8a8>" %}

See the reference of old and new expression formats:

<details>

<summary>See old and new expressions</summary>

\| Value | Expressions | |-------------------------|----------------------------------------------------------------------------------------------------------| | \*\*Workspace ID\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.workspace>\` | | | After: \`<+workspace.identifier>\` | | \*\*Folder Path\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.PLUGIN\_ROOT\_DIR>\` | | | After: \`<+workspace.folderPath>\` | | \*\*Provisioner Type\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.PLUGIN\_PROVISIONER>\` | | | After: \`<+workspace.type>\` | | \*\*Provisioner Version\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.PLUGIN\_TF\_VERSION>\` | | | After: \`<+workspace.provisionerVersion>\` | | \*\*Connector Ref\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.PLUGIN\_CONNECTOR\_REF>\` | | | After: \`<+workspace.connectorRef>\` | | \*\*Env Variable\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.SOME\_ENV\_VAR>\` | | | After: \`<+workspace.envVars.SOME\_ENV\_VAR>\` | | \*\*Terraform/Opentofu var\*\*| Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariables.PLUGIN\_WS\_TF\_VAR\_OPEN\_TOFU\_VAR>\` | | | After: \`<+workspace.variables.OPEN\_TOFU\_VAR>\` | | \*\*Secret Variable\*\* | Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.secretVariables.SECRET\_ENV\_VAR>\` | | | After: \`<+workspace.envVars.SECRET\_ENV\_VAR>\` | | \*\*Output\*\* | Before: \`<+workspace.<+pipeline.stages.s1.spec.execution.steps.init.spec.workspace>.OUTPUT\_ID>\` | | | After: \`<+workspace.outputs.OUTPUT\_ID>\` | | \*\*Env Var from Connector\*\*| Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.envVariablesFromConnector.PLUGIN\_ACCESS\_KEY>\` | | | After: \`<+workspace.envVariablesFromConnector.PLUGIN\_ACCESS\_KEY>\` | | \*\*Secret from Connector\*\*| Before: \`<+pipeline.stages.s1.spec.execution.steps.init.spec.secretVariablesFromConnector.PLUGIN\_SECRET\_KEY>\` | | | After: \`<+workspace.secretVariablesFromConnector.PLUGIN\_SECRET\_KEY>\` |

</details>
{% endtab %}
{% endtabs %}

By understanding and utilizing workspace expressions in Harness IaCM, you can significantly enhance the efficiency and adaptability of your infrastructure management processes.
