Terraform how-tos
Harness has first-class support for HashiCorp Terraform as an infrastructure provisioner.
See the following Terraform How-tos:
- Provision Target Deployment Infra Dynamically with Terraform
- Plan Terraform Provisioning with the Terraform Plan Step
- Provision with the Terraform Apply Step
- Remove Provisioned Infra with the Terraform Destroy Step
- Rollback Provisioned Infra with the Terraform Rollback Step
For a conceptual overview of Harness Terraform integration, see Terraform Provisioning with Harness.
Important: Install Terraform on Delegates
Terraform must be installed on the Delegate to use a Harness Terraform Provisioner. 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.
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
FROM $DELEGATE_IMAGE:$DELEGATE_TAG
USER 0
RUN useradd -u 1001 -g 0 harness
# Install TF
RUN curl -LO https://releases.hashicorp.com/terraform/1.3.1/terraform_1.3.1_linux_amd64.zip \
&& unzip -q terraform_1.3.1_linux_amd64.zip \
&& 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 https://releases.hashicorp.com/terraform/1.3.5/terraform_1.3.5_linux_amd64.zip
unzip terraform_1.3.5_linux_amd64.zip
mv ./terraform /usr/bin/
# Check TF install
terraform --version
References
Download Terraform from Hashicorp.