Connectors & Variable Sources
Add connectors and configure environment variables, OpenTofu/Terraform variables, and variable files 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
How Harness resolves a variable that is defined in more than one place
Before you begin
Create a workspace to have a workspace to attach connectors and variables to.
Workspace edit permission: You need Edit Var on IACM Workspaces 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 and 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
Open the workspace, then select the Connectors and Variables tab.
In the Connectors panel, select + Add Connector.
Select an existing connector from your account, org, or project scope, or select + New Connector to create one.
Supported connectors
HashiCorp Vault (secrets)
Go to What's supported in Harness IaCM for the current list of supported providers. For AWS-specific authentication options, such as OIDC, IRSA, and node role, go to AWS connector authentication.
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 to see which template settings are enforced.
Variable sources
Harness resolves a variable from one of the following sources, listed from highest to lowest priority:
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
In the Connectors and Variables tab, select + Add Variable in the Environment Variables panel.
Enter a Key for the variable name, for example
TF_LOG.Select a Type, and enter a Value. Go to Supported variable value types.
OpenTofu/Terraform variables
OpenTofu/Terraform variables map to the variable {} blocks declared in your OpenTofu or Terraform code.
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.
Add a Terraform variable
In the Connectors and Variables tab, select + Add Variable in the Terraform Variables panel.
Enter a Key that matches the variable name declared in your OpenTofu/Terraform code.
Select a Type, and enter a Value, or use
<+input>to prompt for the value at runtime. Go to Supported variable value types.
If you do not set a value in the workspace, Harness falls back to the default defined in your HCL:
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
3or0.5.Boolean:
trueorfalse.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, .json, or .yaml file stored in Git.
Add a variable file
In the Connectors and Variables tab, select + Add File in the Variable Files panel.
Select the connector to your Git repository.
Select a repository, branch, and file path, for example
envs/dev.tfvars.
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 to create, attach, and prioritize Variable Sets.
Troubleshooting
Next steps
Provision your workspace using the connectors and variables you configured.
Add OPA policies to enforce policy compliance on your workspace.
Last updated
Was this helpful?