> 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/platform/iacm-connectors-variables/connectors-variables.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Connectors & Variable Sources

Add connectors and configure environment variables, OpenTofu/Terraform variables, variable files, and file secrets for an IaCM workspace.

**Connectors** and **variable sources** define the inputs and integrations a workspace uses when Harness runs **Plan**, **Apply**, or **Drift detection** pipelines. A variable can come from several sources, and Harness resolves conflicts using a clear order of precedence.

## What you will learn from this topic

* How to add a connector to a workspace
* How to add environment variables and OpenTofu/Terraform variables, and which value types they support
* How to add a variable file and set which variable file takes precedence when files define the same variable
* How to provide a file secret to an IaCM pipeline step
* How Harness resolves a variable that is defined in more than one place

## Before you begin

* [Create a workspace](https://developer.harness.io/infrastructure-as-code-management/platform/workspaces/create-workspace.md) to have a workspace to attach connectors and variables to.
* **Workspace edit permission:** You need **Edit Var** on [IACM Workspaces](https://developer.harness.io/harness-platform/use-harness-platform/platform-access-control/permissions-reference#infrastructure-as-code) to add or update connectors and variables. To get this permission, an administrator must assign you a role that includes it. Go to [RBAC in Harness](https://developer.harness.io/harness-platform/use-harness-platform/platform-access-control) and [Manage roles](https://developer.harness.io/harness-platform/use-harness-platform/platform-access-control/add-manage-roles) to configure roles.

***

## Connectors

A connector authenticates a workspace to a cloud provider, Git provider, or secrets manager. Most workspace operations, such as fetching modules or variable files, depend on a connector.

### Add a connector

1. Open the workspace, then select the **Connectors and Variables** tab.
2. In the **Connectors** panel, select **+ Add Connector**.
3. Select an existing connector from your account, org, or project scope, or select **+ New Connector** to create one.

### Supported connectors

| Provider                  | Go to                                                                                                                                                                  |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AWS                       | [Add an AWS connector](https://developer.harness.io/harness-platform/use-harness-platform/connectors/cloud-providers/add-aws-connector)                                |
| GCP                       | [Connect to Google Cloud Platform](https://developer.harness.io/harness-platform/use-harness-platform/connectors/cloud-providers/connect-to-google-cloud-platform-gcp) |
| Azure                     | [Add a Microsoft Azure connector](https://developer.harness.io/harness-platform/use-harness-platform/connectors/cloud-providers/add-a-microsoft-azure-connector)       |
| HashiCorp Vault (secrets) | [Add a HashiCorp Vault connector](https://developer.harness.io/harness-platform/use-harness-platform/secrets/secrets-management/add-hashicorp-vault)                   |

Go to [What's supported in Harness IaCM](https://developer.harness.io/infrastructure-as-code-management/troubleshooting-and-resources/whats-supported.md) for the current list of supported providers. For AWS-specific authentication options, such as OIDC, IRSA, and node role, go to [AWS connector authentication](https://developer.harness.io/infrastructure-as-code-management/platform/iacm-connectors-variables/aws-connector-auth.md).

IaCM supports Azure OIDC connectors for Terraform, OpenTofu, and Terragrunt workspaces. To configure the connector, go to [Add a Microsoft Azure connector](https://developer.harness.io/harness-platform/use-harness-platform/connectors/cloud-providers/add-a-microsoft-azure-connector#oidc-authentication).

You must also set `ARM_SUBSCRIPTION_ID` as a workspace environment variable. The Azure OIDC connector does not provide a subscription ID, so the AzureRM provider fails to initialize if this variable is not set.

{% hint style="info" %}
If `ARM_CLIENT_ID` is already set as a workspace environment variable, the IaCM plugin uses the existing `ARM_*` environment variables instead of the connector. To use the connector for authentication, remove `ARM_CLIENT_ID`, `ARM_CLIENT_SECRET`, and `ARM_TENANT_ID` from your workspace environment variables.
{% endhint %}

### Multiple connectors

A workspace can use more than one connector, for example to reach both AWS and Azure from the same workspace. A workspace can have only one connector per provider type.

If a workspace uses a workspace template, connectors defined in the template appear automatically and cannot be modified in the workspace. Go to [Locked fields](https://developer.harness.io/infrastructure-as-code-management/platform/workspaces/workspace-templates.md#locked-fields) to see which template settings are enforced.

To authenticate a single workspace to more than one AWS account in the same run, go to [Multiple AWS OIDC accounts](https://developer.harness.io/infrastructure-as-code-management/platform/iacm-connectors-variables/aws-connector-auth/multiple-aws-oidc-accounts.md).

***

## Variable sources

Harness resolves a variable from one of the following sources, listed from highest to lowest priority:

| Priority    | Source                                                                  |
| ----------- | ----------------------------------------------------------------------- |
| 1 (highest) | Workspace Template variables                                            |
| 2           | Workspace-level variables (environment or OpenTofu/Terraform variables) |
| 3           | Variable Sets, in their assigned priority order                         |
| 4 (lowest)  | Default values in your OpenTofu/Terraform code (HCL)                    |

If a variable with the same name exists in more than one source, Harness uses the value from the highest-priority source.

***

## Environment variables

Environment variables behave like standard shell variables. Your provisioning logic, module behavior, or CLI tooling can read them at runtime.

### Add an environment variable

1. In the **Connectors and Variables** tab, select **+ Add Variable** in the **Environment Variables** panel.
2. Enter a **Key** for the variable name, for example `TF_LOG`.
3. Select a **Type**, and enter a **Value**. Go to [Supported variable value types](#supported-variable-value-types).

```yaml
# Example: static and runtime-injected environment variables
environmentVariables:
  - key: TF_LOG
    value: INFO
    type: String
    source: CUSTOM
  - key: ENVIRONMENT
    value: <+input>
    type: String
    source: CUSTOM
```

{% hint style="info" %}
**RUNTIME INPUT**

Use `<+input>` as a value to prompt the pipeline executor for a value at runtime.
{% endhint %}

***

## OpenTofu/Terraform variables

OpenTofu/Terraform variables map to the `variable {}` blocks declared in your OpenTofu or Terraform code.

{% hint style="warning" %}
**AWS CDK WORKSPACES**

The **Terraform Variables** panel still appears for AWS CDK workspaces, but AWS CDK does not consume these variables. Adding or updating a Terraform variable in a CDK workspace has no effect.
{% endhint %}

### Add a Terraform variable

1. In the **Connectors and Variables** tab, select **+ Add Variable** in the **Terraform Variables** panel.
2. Enter a **Key** that matches the variable name declared in your OpenTofu/Terraform code.
3. Select a **Type**, and enter a **Value**, or use `<+input>` to prompt for the value at runtime. Go to [Supported variable value types](#supported-variable-value-types).

```yaml
# Example: workspace-level Terraform variable
terraformVariables:
  - key: instance_type
    value: t3.large
    type: String
    source: CUSTOM
```

If you do not set a value in the workspace, Harness falls back to the `default` defined in your HCL:

```hcl
# main.tf
variable "instance_type" {
  type    = string
  default = "t3.micro"
}
```

### Supported variable value types

Environment variables and OpenTofu/Terraform variables support the following value types:

* **String**: Free-form text, for example `t3.large`.
* **Secret**: A reference to a Harness secret. Harness masks the value in the UI and logs.
* **Number**: An integer or decimal value, for example `3` or `0.5`.
* **Boolean**: `true` or `false`.
* **JSON**: A JSON object or array, for example `{"env": "prod"}`.

Select the type that matches the value your provisioning logic or code expects. Harness validates the value against the selected type when you save the variable.

***

## Variable files

Variable files inject multiple variables at once from a `.tfvars` (HCL) or `.json` file stored in Git.

### Add a variable file

1. In the **Connectors and Variables** tab, select **+ Add File** in the **Variable Files** panel.
2. Select the connector to your Git repository.
3. Select a repository, branch, and file path, for example `envs/dev.tfvars`.

```yaml
# Workspace variable file definition
variableFiles:
  - type: Git
    spec:
      connectorRef: account.git_connector
      repoName: terraform-configs
      branch: main
      paths:
        - envs/dev.tfvars
```

{% hint style="info" %}
Your variable files and your OpenTofu/Terraform code can come from the same Git repository or from different repositories. You can add more than one variable file to a workspace.
{% endhint %}

### Variable file priority

When two variable files define the same variable, the file that OpenTofu or Terraform loads last takes precedence. Variable file priority lets you control this precedence. The file at the top of a **Variable Files** panel has Priority 1, the highest priority in that panel.

You can set variable file priority in two places:

* **On a workspace:** The **Variable Files** panel lists only the variable files that you add to the workspace manually. You cannot reorder files that come from an attached Variable Set on the workspace page.
* **In a Variable Set:** Each Variable Set has its own **Variable Files** panel that orders the files the set contains.

To set the priority of workspace variable files:

1. Open the workspace, then select the **Connectors and Variables** tab.
2. In the **Variable Files** panel, drag the files into the desired order, with the highest-priority file at the top.
3. Save the workspace.

To set the priority of the variable files in a Variable Set:

1. Go to **Account Settings**, **Organization Settings**, or **Project Settings**, then select **IaCM Settings**.
2. Select **Variable Sets**, then open the Variable Set.
3. In the **Variable Files** panel, drag the files into the desired order, with the highest-priority file at the top.
4. Save the Variable Set.

Go to [Variable Sets](https://developer.harness.io/infrastructure-as-code-management/platform/iacm-connectors-variables/variable-sets.md) to learn how to attach a Variable Set to a workspace and set Variable Set priority.

### How Harness orders files from the workspace and Variable Sets

When Variable Sets that contain variable files are attached to the workspace, Harness resolves precedence in this order:

1. **Workspace variable files:** Files that you add manually to the workspace always have the highest priority, in the order set in the workspace **Variable Files** panel.
2. **Variable Set files:** Files from attached Variable Sets follow the priority of the Variable Sets on the workspace, from the Priority 1 Variable Set to the last. Within each Variable Set, files follow the order set in that Variable Set.

For example, a workspace has two manually added variable files, and two attached Variable Sets that each contain two variable files. Variable Set 1 has a higher priority than Variable Set 2 on the workspace.

| Source         | Files in priority order |
| -------------- | ----------------------- |
| Workspace      | `ws_p1`, `ws_p2`        |
| Variable Set 1 | `vs1_p1`, `vs1_p2`      |
| Variable Set 2 | `vs2_p1`, `vs2_p2`      |

The final priority, from highest to lowest, is `ws_p1`, `ws_p2`, `vs1_p1`, `vs1_p2`, `vs2_p1`, `vs2_p2`.

The IaCM step logs show the resolved order using `Using variable file (priority-ordered): <path>`, from highest to lowest priority.

{% hint style="info" %}
**Behavior without variable file priority**

Before variable file priority is enabled, Harness sorts variable files alphabetically by file path, and the file that sorts last takes precedence. Enabling variable file priority preserves the existing effective order, so existing variable values do not change until you reorder the files.
{% endhint %}

***

## File secrets <a href="#file-secrets" id="file-secrets"></a>

IaCM workspace variables store string values only. To provide a file — such as a provider configuration file, a `.tofurc` registry credentials file, or a custom CA bundle — to an IaCM pipeline step, use a **Run** step to write the file content to disk before the IaCM steps execute.

### Write a file secret to disk <a href="#write-a-file-secret-to-disk" id="write-a-file-secret-to-disk"></a>

1. Store the file content as a Harness secret (type **Secret Text**). Go to [Manage secrets](https://developer.harness.io/harness-platform/use-harness-platform/secrets) to create one.
2. Add a **Run** step as the first step in your IaCM stage, before the `init` step.
3. In the Run step, write the secret value to a temporary path.
4. Set the path as a workspace environment variable so the IaCM steps can find it.

```yaml
- step:
    type: Run
    name: write-cli-config
    identifier: write_cli_config
    spec:
      shell: Sh
      command: echo "$TF_CONFIG_CONTENT" > /tmp/.tofurc
      envVariables:
        TF_CONFIG_CONTENT: <+secrets.getValue("tofurc_content")>
- step:
    type: IACMTerraformPlugin
    name: init
    identifier: init
    spec:
      command: init
```

Add `TF_CLI_CONFIG_FILE: /tmp/.tofurc` as a workspace environment variable so every subsequent OpenTofu step in the stage inherits it.

{% hint style="info" %}
The Run step and the IaCM steps share the stage file system. A file written by the Run step is available to all subsequent steps in the same stage.
{% endhint %}

***

## Variable sets

A Variable Set is a reusable collection of connectors, environment variables, OpenTofu/Terraform variables, and secrets that you can attach to multiple workspaces from the **Connectors and Variables** tab.

Go to [Variable Sets](https://developer.harness.io/infrastructure-as-code-management/platform/iacm-connectors-variables/variable-sets.md) to create, attach, and prioritize Variable Sets.

***

## FAQs <a href="#faqs" id="faqs"></a>

<details>

<summary>Can I reference tfvars files from a different Git repository than my workspace code?</summary>

Yes. Variable files and your IaC code can come from different repositories. When you add a variable file under the **Variable Files** panel, you select the Git connector, repository, branch, and file path independently of the repository configured in the workspace's **Provisioner** section. This means you can keep shared variable files in a central repository and reference them from any workspace.

Go to [Add a variable file](#variable-files) for the configuration steps and YAML example.

</details>

***

## Troubleshooting

<details>

<summary>Saving a Number, Boolean, or JSON variable fails with a validation error</summary>

The value does not match the selected type. Confirm that a **Number** value contains only digits (and an optional decimal point), a **Boolean** value is `true` or `false`, and a **JSON** value is valid JSON, then save the variable again.

</details>

<details>

<summary>Updating a Terraform variable has no effect on an AWS CDK workspace</summary>

AWS CDK does not consume the **Terraform Variables** panel. The panel still appears on an AWS CDK workspace, but any value you add or update there is ignored. Pass values to CDK through its own configuration instead.

</details>

<details>

<summary>A variable is not using the value I expect</summary>

The same variable name can be defined in more than one source. Go to [Variable sources](#variable-sources) to check the order of precedence, and confirm whether a Workspace Template or a higher-priority Variable Set is overriding the value you set.

</details>

<details>

<summary>The wrong variable file takes precedence when two files define the same variable</summary>

Check the order in the step log, which lists each file as `Using variable file (priority-ordered): <path>` from highest to lowest priority. If the log shows files without the `priority-ordered` label, variable file priority is not enabled for the run, and Harness sorts the files alphabetically by file path. Go to [Variable file priority](#variable-file-priority) to reorder the files.

</details>

***

## Next steps

* [Provision your workspace](https://developer.harness.io/infrastructure-as-code-management/platform/workspaces/provision-workspace.md) using the connectors and variables you configured.
* [Add OPA policies](https://developer.harness.io/infrastructure-as-code-management/platform/policy-and-governance/opa-workspace.md) to enforce policy compliance on your workspace.
* [Custom images for OpenTofu](https://developer.harness.io/infrastructure-as-code-management/use-iacm/iac-provisioners/opentofu/custom-images.md): build a custom plugin image to pre-install binaries, providers, or configuration files such as `.tofurc` into your pipeline environment.

{% @harness-feedback/feedback %}
