Skip to main content

Terraform how-tos

Harness has first-class support for HashiCorp Terraform as an infrastructure provisioner.

You can use Harness with Terraform in the following ways:

  • Local provisioning: you can run configuration files on the Harness delegate(s) installed in your environment.
  • Terraform Cloud/Enterprise: you can run Terraform Cloud workspaces by connecting Harness to your Terraform Cloud account.

You can do both methods in the same stage if you want.

For a conceptual overview of Harness Terraform integration, see Terraform Provisioning with Harness.

Running Terraform Cloud workspaces how-tos

In addition to running Terraform configuration files locally on the Harness delegate, Harness supports running Terraform Cloud and Enterprise workspaces.

For more information, go to Terraform Cloud deployments.

Running Terraform locally how-tos

You can use the Harness Terraform steps to provision any resources. You simply add the steps in the Deploy or Custom stage Execution.

For steps on how to run Terraform configuration files on Harness delegates installed in your environment, go to:

Important: Install Terraform on delegates

Terraform must be installed on the delegate to use local Terraform configuration files in Harness Terraform steps. This is not required for running Terraform Cloud/Enterprise workspaces.

You can install Terraform manually or use the INIT_SCRIPT environment variable in the Delegate YAML.

See Build custom delegate images with third-party tools.

The Harness delegate uses RedHat Universal Base Image (redhat/ubi8).

Here's an example of the script to install Terraform:


# Update the system and install necessary tools
sudo yum update -y
sudo yum install -y curl unzip

# Install Terraform
unzip terraform_${TERRAFORM_VERSION}
sudo install terraform /usr/local/bin/
rm terraform_${TERRAFORM_VERSION}

# Check TF install
terraform --version

Target OS and architecture

You will need to change the following scripts based on the operating system and architecture of the machine that is running the delegate.

  • Linux on x86(Intel or AMD): linux_amd64
  • Linux on Arm: linux_arm64
  • MacOs on x86(Intel): darwin_amd64
  • MacOs on ARM(Apple): darwin_arm64

Custom delegate image

The recommended method for installing third party tools on your delegate is to create your own delegate image, push it to a container registry, and then to modify your delegate deployments to use your new custom image.

For more information, go to Build custom delegate images with third-party tools.

ARG DELEGATE_TAG=23.03.78705
ARG DELEGATE_IMAGE=harness/delegate


RUN useradd -u 1001 -g 0 harness

# Install TF
RUN curl -LO \
&& unzip -q \
&& mv ./terraform /usr/bin/ \
&& terraform --version

USER 1001

Init script

Alternatively, you can install Terraform when a delegate pod is launched by specifying an initialization script in the delegate YAML INIT_SCRIPT environment variable.

# Install TF  
microdnf install unzip
curl -O -L
mv ./terraform /usr/bin/

# Check TF install
terraform --version


Download Terraform from Hashicorp.