> 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/harness-ai/use-harness-platform/connectors/cloud-providers/add-a-terraform-cloud-connector.md).

# Add a Terraform Cloud connector

Connect Harness to Terraform Cloud.

Use a Harness Terraform Cloud connector to connect Harness to your Terraform Cloud organization. Use the Terraform Cloud connector to run Terraform Cloud workspaces and runs from Harness pipelines.

***

## What you will learn from this topic

* How to [create a Terraform Cloud connector](#create-a-terraform-cloud-connector) using the Harness Manager.
* How to define a Terraform Cloud connector using a [YAML example](#yaml-example).

***

## Before you begin

* **Terraform Cloud URL**: The URL of your Terraform Cloud or Terraform Enterprise instance, for example `https://app.terraform.io`.
* **Terraform Cloud API token**: A Terraform Cloud API token, stored as a Harness secret. Go to [API Tokens](https://developer.hashicorp.com/terraform/cloud-docs/users-teams-organizations/api-tokens) in the Terraform Cloud documentation to generate a user, team, or organization token, then store the token value as a Harness secret.
* **Harness Delegate**: A running Harness Delegate that can reach your Terraform Cloud instance. Go to [Delegate installation overview](/harness-ai/use-harness-platform/delegates/delegate/install-delegates/overview.md) to install one. Connect through a Harness Delegate rather than the Harness Platform, because you need a delegate later to run Terraform Cloud steps in your pipelines.

### Minimum permissions <a href="#minimum-permissions" id="minimum-permissions"></a>

The Terraform Cloud API token must allow the following operations:

* **List organizations**: Required for the connector's connection test. If the token cannot list organizations, the connection test fails.
* **Create, apply, and discard runs, and lock, unlock, and manage state versions for the target workspace**: Required if you use the token with the Terraform Cloud Run or Terraform Cloud Rollback pipeline steps.

{% hint style="warning" %}
**Confirm the exact token scope with your Terraform Cloud administrator**

Harness does not enforce a specific Terraform Cloud token type (user, team, or organization). Grant the token whichever scope covers the operations above for the organizations and workspaces the connector accesses.
{% endhint %}

***

## Create a Terraform Cloud connector <a href="#create-a-terraform-cloud-connector" id="create-a-terraform-cloud-connector"></a>

Perform the following steps to create the Terraform Cloud connector using the Harness Manager.

1. Open a Harness project, and select **Connectors** under **Project Setup**. You can also create connectors at the account or organization levels.
2. Select **New Connector**, and then select **Terraform Cloud** under **Cloud Providers**.

### Overview <a href="#overview" id="overview"></a>

Enter a **Name** for the connector. **Description** and **Tags** are optional. Harness automatically creates an **Id** ([entity identifier](/harness-ai/use-harness-platform/references/entity-identifier-reference.md)) for the connector based on the **Name**. Select **Continue** to proceed to **Credentials**.

![Overview step of the Terraform Cloud connector wizard](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-75f35b933ec6b04e21a276c5ee6e0e5e1d49c075%2Fterraformcloud-conenction-overview.png?alt=media)

### Credentials <a href="#credentials" id="credentials"></a>

Select **Continue** after entering the following details:

* **Terraform Cloud URL**: Enter your Terraform Cloud or Terraform Enterprise URL, for example `https://app.terraform.io`.
* **API Token**: Select **Create or Select a Secret** to add your Terraform Cloud API token. Go to [Before you begin](#before-you-begin) for how to generate the token.

![Credentials step of the Terraform Cloud connector wizard](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-f82895eb5d2a9d615193797df6207498465d3c6e%2Fterraformcloud-connection-credentials.png?alt=media)

### Select Connectivity Mode <a href="#select-connectivity-mode" id="select-connectivity-mode"></a>

Under **Connect to the provider**, select how you want Harness to connect to Terraform Cloud, and then select **Save and Continue**:

* **Connect through Harness Platform**: Harness communicates with Terraform Cloud securely through the Harness Platform. Credentials are encrypted and stored in the Secret Manager configured in Harness.
* **Connect through a Harness Delegate**: Harness communicates with Terraform Cloud through a Harness Delegate installed in your environment. Select this option if Terraform Cloud is behind a corporate firewall.

![Select Connectivity Mode step of the Terraform Cloud connector wizard](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-760cf501ba736f9f996e16fa3316e68e40f0093e%2Fterraformcloud-delegate-setup.png?alt=media)

{% hint style="info" %}
A Harness Delegate is used for deployment operations even if you select **Connect through Harness Platform**.
{% endhint %}

### Delegates Setup <a href="#delegates-setup" id="delegates-setup"></a>

This step appears only if you selected **Connect through a Harness Delegate**. Select one of the following options, and then select **Save and Continue**:

* **Use any available Delegate**.
* **Only use Delegates with all of the following tags**: Enter the tag of the [delegate](#before-you-begin) you installed.

![Delegates Setup step of the Terraform Cloud connector wizard](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-883a5745d2f21a117aa6a533de685a73ec343d1b%2Fterraformcloud-connection-delegate.png?alt=media)

### Connection Test <a href="#connection-test" id="connection-test"></a>

Harness validates the Terraform Cloud connector authentication and permissions. Once verification succeeds, select **Finish**.

![Connection Test step of the Terraform Cloud connector wizard](https://173309742-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3F2TpHXhur2QtQnORSM9%2Fuploads%2Fgit-blob-4973048932f8f89d0c56da528fe60612c5b43c03%2Fterraformcloud-connection-details.png?alt=media)

The connector now appears in the **Connectors** list.

{% hint style="warning" %}
**Limitations**

The Terraform Cloud connector supports API token authentication only. Harness does not validate whether the **Terraform Cloud URL** points to Terraform Cloud (SaaS) or a self-hosted Terraform Enterprise instance, so connectivity depends on the instance implementing the same API endpoints Harness calls.
{% endhint %}

***

## YAML example <a href="#yaml-example" id="yaml-example"></a>

The following YAML defines a Terraform Cloud connector that authenticates using an API token and connects through a Harness Delegate.

<details>

<summary>Terraform Cloud connector YAML</summary>

```yaml
connector:
  name: tf-cloud # Connector display name shown in the Harness UI
  identifier: tfcloud # Unique connector identifier, cannot be changed after creation
  description: "" # Optional description for the connector
  accountIdentifier: <YOUR_ACCOUNT_ID> # Harness account identifier that owns the connector
  orgIdentifier: default # Harness org identifier that owns the connector
  projectIdentifier: <YOUR_PROJECT_ID> # Harness project identifier that owns the connector
  type: TerraformCloud
  spec:
    terraformCloudUrl: https://app.terraform.io # Terraform Cloud or Terraform Enterprise URL
    credential:
      type: ApiToken
      spec:
        apiToken: account.<YOUR_TERRAFORM_CLOUD_TOKEN_SECRET_REF> # Harness secret reference storing your Terraform Cloud API token
    executeOnDelegate: true # Set to false to connect through the Harness Platform instead of a delegate
    ignoreTestConnection: false # Set to true to skip the connection test when the connector is saved
```

</details>

***

## Next steps

* [Delegate installation overview](/harness-ai/use-harness-platform/delegates/delegate/install-delegates/overview.md): Install and configure a Harness Delegate for your Terraform Cloud connector.
* [Terraform Cloud Provisioning](https://developer.harness.io/continuous-delivery/use-continuous-delivery/provision-infrastructure/terraform-infra/terraform-cloud-deployments): Use the connector in a Harness Deploy stage to run and roll back Terraform Cloud workspaces.

{% @harness-feedback/feedback module="harness-ai" pagePath="harness-ai/use-harness-platform/connectors/cloud-providers/add-a-terraform-cloud-connector" %}
