Terraform Cloud provisioning
In addition to running Terraform configuration files locally on the Harness Delegate, Harness supports running Terraform Cloud and Enterprise workspaces.
This topic explains how to run your Terraform Cloud and Enterprise workspaces in Harness CD stages.
Running Terraform locally
For details on running Terraform configuration files locally on the delegate, go to:
Important notes
- The workspace in Terraform Cloud should be configured and connected to the configuration files repo. Execution mode should be set to Remote. Currently, Harness can be used only for running executions in the workspace.
- User/role permissions required by the target platform (AWS, GCP, etc) in order to perform tasks: You should create an API token in Terraform Cloud that can be used in the Harness connector that connects Harness to Terraform Cloud. You can create User or Team API tokens. Organization tokens can’t be used for run creation. For more information about the required privileges, review the API tokens access levels from HashiCorp.
- You can add Terraform Cloud steps in any CD or Custom stage.
Harness connector
The Harness Terraform Cloud connector connects your Harness account with your Terraform Cloud or Enterprise account.
You can the Terraform Cloud connector and then select it in each of the Terraform Cloud steps you add to your pipeline.
The Terraform Cloud connector uses a Terraform Cloud API token for authentication.
To add the Terraform Cloud connector, do the following:
- YAML
- API
- Pipeline Studio
The following is an example of the YAML for a Terraform Cloud connector.
Terraform Cloud connector YAML example
connector:
name: TF Cloud connector
identifier: TF_Cloud_connector
description: ""
orgIdentifier: default
projectIdentifier: TerraformCloud_Doc_team
type: TerraformCloud
spec:
terraformCloudUrl: https://app.terraform.io
credential:
type: ApiToken
spec:
apiToken: account.terraformconnector
executeOnDelegate: true
Create the Terraform Cloud connector using the Create a Connector API.
Terraform Cloud connector API example
curl --location --request POST 'https://app.harness.io/gateway/ng/api/connectors?accountIdentifier=12345' \
--header 'Content-Type: text/yaml' \
--header 'x-api-key: pat.12345.6789' \
--data-raw 'connector:
name: TF Cloud connector
identifier: TF_Cloud_connector
description: ""
orgIdentifier: default
projectIdentifier: TerraformCloud_Doc_team
type: TerraformCloud
spec:
terraformCloudUrl: https://app.terraform.io
credential:
type: ApiToken
spec:
apiToken: account.terraformconnector
executeOnDelegate: true'
To add a Terraform Cloud connector, do the following:
- In your Harness project, select Project Setup, and then select Connectors.
- Select New Connector, and then select Terraform Cloud.
- Enter a name for the connector and click Continue.
- Enter the URL for Terraform Cloud, such as
https://app.terraform.io
. - In API Token, create or select a Harness secret containing your Terraform Cloud API token, and then select Continue.
- In Connect to the provider, select whether to connect using a delegate or Harness Platform, and then select Continue or Save and Continue.
- If you selected to connect using a delegate, select one or more delegates.
- Select Finish. Harness verifies the connection.

Terraform Cloud Run step
The Terraform Cloud Run step uses the Terraform Cloud connector you added to connect to your Terraform Cloud/Enterprise account and run your workspaces.
Run Type
The Terraform Cloud Run step can perform the following run types.
Supported run types
- Plan: A plan is a Terraform Cloud run that generates an execution plan that describes the changes that Terraform will make to the infrastructure in order to match the configuration code. The plan step is typically used to preview changes before actually applying them. It provides insights into what resources will be created, modified, or destroyed, and what actions will be taken by Terraform to achieve the desired state.
- Apply: An apply run is a Terraform Cloud run that applies the changes described in the execution plan generated by a previous plan run. The apply step is used to make the actual changes to the infrastructure resources based on the configuration code. When an apply run is executed, Terraform will create, modify, or destroy resources as needed to bring the infrastructure into the desired state.
- Refresh: A refresh run is a Terraform Cloud run that updates the state of the infrastructure resources with the current state of the cloud environment. This can be useful if there have been changes made to the infrastructure outside of Terraform, and you need to update the state to reflect those changes.
- Plan Only: A plan-only run is a Terraform Cloud run that generates an execution plan but cannot apply it. This can be useful for previewing changes and verifying that the desired changes will be made without actually applying them.
- Plan and Apply: A plan-and-apply run is a Terraform Cloud run that generates an execution plan and then applies the changes to the infrastructure based on that plan. This is a combination of the plan and apply steps, and is often used when you're confident in the changes that will be made and want to apply them without previewing them first.
- Plan and Destroy: A plan-and-destroy run is a Terraform Cloud run that generates an execution plan and then destroys all of the infrastructure resources that are managed by the Terraform configuration. This can be useful if you want to delete the entire infrastructure environment, such as when decommissioning a project or environment.