Harness Terraform Provider is a library that you can use to create Harness Infrastructure. You can administer and use Harness functionality from within your Terraform setup using Harness Terraform Provider. It serves as an interface to the Harness API, enabling you to create and manage Harness infrastructure using Terraform commands.
The Terraform tool enables the management and provisioning of infrastructure through code. Using Terraform, you can easily build, modify, and version low-level components like compute instances, storage, and networking, as well as high-level components like DNS entries and SaaS features. When combined with Harness, Terraform becomes a first-class step in delivery pipelines rather than a side activity.
How the Harness Terraform Provider Works
When you configure the Harness Terraform Provider, you will need to provide credentials that Terraform can use to authenticate with Harness, and trigger creation and management of resources within Harness as per the config file provided to Terraform.
The provider maps to Harness CD and NextGen platforms. The Terraform provider for Harness allows you to manage resources in Harness CD and NextGen platforms using infrastructure as code.
Provider authentication can be supplied directly in configuration or via environment variables. A collection of Terraform resources used to support the base structure of the Harness Platform exists to make adoption easier. This collection of Terraform modules focuses on the initial setup of Harness Platform configurations and base functionality.
Environment variable authentication is supported as follows:
- HARNESS_ENDPOINT: Harness Platform URL, defaults to Harness SaaS URL: https://app.harness.io/gateway
- HARNESSACCOUNTID: Harness Platform Account Number
- HARNESSPLATFORMAPI_KEY: Harness Platform API Key for your account
The module requires that the calling template has defined the Harness Provider - Docs authentication.
Variable definitions for provider setup commonly include:
hcl
variable "harness_platform_url" {
type = string
description = "[Optional] Enter the Harness Platform URL
}
Once the provider is set up, you can use it to provision your Harness resources. The Terraform template-based configuration file syntax enables you to configure Harness resources in a repeatable and predictable manner. This lowers the potential for human errors while deploying and managing infrastructure.
Harness Terraform Provider makes it easy to scale infrastructure up and down as needed, improving the overall scalability of your infrastructure.
Setup Sequence for Harness Terraform Provider
To create and modify Harness resources using the Harness Terraform Provider, you will need to do the following:
- Install the Terraform CLI
- Configure your Harness credentials
- Install the Harness Provider
- Add your credentials to the appropriate Terraform config file.
- Build infrastructure
- Modify infrastructure
- Destroy infrastructure
The workflow is linear and repeatable. Harness provides a sample Terraform deployment repository for reference and reuse.
A typical provider block looks like:
```hcl
terraform {
required_providers {
harness = {
source = "harness/harness"
version = "~> 0.1"
}
}
}
provider "harness" {
endpoint = var.harnessplatformurl
accountid = var.harnessaccountid
apikey = var.harnessplatformapi_key
}
```
After provider configuration, resource definitions are written declaratively and versioned in Git.
Native Terraform Support in Harness Pipelines
Harness is a modern CI/CD platform that provides intelligent deployment verification, automated rollbacks, and cost management. Integrating Terraform with Harness allows you to include infrastructure provisioning as a first-class step in your delivery pipelines. Harness offers native Terraform support, making it straightforward to plan, apply, and destroy infrastructure as part of your deployment workflows.
Harness brings several advantages to Terraform workflows. Its native Terraform integration provides plan approval workflows, state management, and drift detection. Harness's AI-powered verification can validate that infrastructure changes do not cause service degradation.
The pairing of continuous delivery discipline with declarative infrastructure logic produces repeatable IaC workflows with governance baked in. Harness runs infrastructure as pipelines, checks policy, and rolls back safely. Terraform keeps the underlying cloud definitions clean and portable. The pairing’s real power is control without friction.
Harness connects to your Terraform state via API or remote backend. It maps roles from your identity provider — say Okta, AWS IAM, or Google Workspace — onto pipeline permissions. Each deployment triggers Terraform using predefined variables and scripts, but the security and approval flow live in Harness. Secrets rotate automatically via encrypted vault integrations. Every run is logged, versioned, and tied to user identity through OIDC. It is policy-controlled IaC without the usual safety net of hope.
If Terraform already automates your infrastructure, Harness automates the automation itself. That loop removes hours of context switching.
Governance, Approvals and Policy Enforcement
Complex resource configurations can make it difficult to understand the meaning and impact of infrastructure changes. The Terraform CLI lets you validate and preview infrastructure changes before applying them. Previewing infrastructure changes safely has several benefits:
- Team members can collaborate more effectively by understanding proposed changes and their impact.
- Unintended changes can be caught early in the development process.
Implementation practices recommended for production use include:
- Implement approval gates between Terraform plan and apply stages.
- Use OPA policies to enforce organizational standards on infrastructure changes.
- Leverage Harness's verification capabilities to validate infrastructure health after Terraform applies.
- Store Terraform configurations in Git and reference them through Harness connectors.
- Use pipeline templates for consistent Terraform workflows across teams.
- Monitor deployment frequency and failure rates to improve your pipeline over time.
Approval gates ensure that a Terraform plan is reviewed before apply is permitted. OPA policies can enforce tagging standards, cost controls, and security baselines. Verification capabilities validate infrastructure health after Terraform applies, providing automated rollbacks when degradation is detected.
Your Terraform module just finished deploying, but now the DevOps team wants a full audit trail, cost visibility, and security policy approval before production. Instead of juggling manual scripts, CI templates, and compliance emails, you wire it through Harness Terraform and suddenly the pipeline feels civilized. No more guessing who changed what or chasing environment drift across clouds.
State Management and Drift Detection
Harness native Terraform integration provides plan approval workflows, state management, and drift detection. State is stored securely and accessed through Harness connectors. Drift detection compares live Harness resources against the declared Terraform state and surfaces discrepancies.
Table 1 compares key capabilities of standalone Terraform versus Harness-managed Terraform.
| Capability | Standalone Terraform | Harness + Terraform |
|---|---|---|
| Provisioning | Declarative via CLI | Declarative via CLI in pipeline |
| Plan preview | Terraform plan locally | Plan in pipeline with audit |
| Approval | Manual | Built-in approval gates |
| State storage | Local or remote backend | Managed with state locking |
| Drift detection | Manual | Automated detection |
| Policy enforcement | External | OPA policies in pipeline |
| Verification | Post-deploy manual | AI-powered verification |
| Rollback | Manual | Automated rollbacks |
Community Structure and Base Modules
The goal of the community structure repository is to provide simple to consume versions of the Harness Terraform resources in such a way to make the management of Harness via Terraform easy to adopt.
This collection of Terraform modules focuses on the initial setup of Harness Platform configurations and base functionality. You can also set up authentication with Harness through environment variables. To do this set the following items in your environment:
- HARNESS_ENDPOINT: Harness Platform URL, defaults to Harness SaaS URL: https://app.harness.io/gateway
- HARNESSACCOUNTID: Harness Platform Account Number
- HARNESSPLATFORMAPI_KEY: Harness Platform API Key for your account
The structure provides a base for defining accounts, organizations, projects, and pipeline entities as code.
Harness welcomes contributions to the Harness Terraform Provider.
Practical Pipeline Flow
A typical Harness pipeline with Terraform includes:
- Source stage: pull Terraform configuration from Git
- Plan stage: run terraform plan, store plan artifact
- Approval stage: human or policy approval gate
- Apply stage: run terraform apply with locked state
- Verify stage: run Harness verification checks
- Notify stage: publish results and audit logs
Secrets are injected via Harness secrets manager and rotated automatically. Identity mapping ensures each execution is tied to a user through OIDC.
Benefits of Codified Delivery
Terraform and Harness together provide a robust infrastructure and application delivery platform. Harness's native Terraform integration adds governance, approval workflows, and verification capabilities that complement Terraform's infrastructure provisioning strengths. By managing your Harness configuration with Terraform itself, you achieve a fully codified delivery pipeline that is reproducible, auditable, and scalable.
Repeatability comes from versioned Terraform modules and pipeline templates. Auditability comes from logs, plan artifacts, and identity-tied executions. Scalability comes from reusable modules and centralized policy.
The Terraform template-based configuration file syntax enables you to configure Harness resources in a repeatable and predictable manner. This lowers the potential for human errors while deploying and managing infrastructure.
Harness Terraform Provider makes it easy to scale infrastructure up and down as needed, improving the overall scalability of your infrastructure.
Table 2 summarizes environment variables for provider authentication.
| Variable | Description | Default |
|---|---|---|
| HARNESS_ENDPOINT | Harness Platform URL | https://app.harness.io/gateway |
| HARNESSACCOUNTID | Harness Platform Account Number | required |
| HARNESSPLATFORMAPI_KEY | Harness Platform API Key for your account | required |
Conclusion
Harness Terraform Provider and native Terraform integration address the operational gap between declarative infrastructure definition and governed delivery. The provider exposes Harness CD and NextGen resources to Terraform, allowing infrastructure as code for the delivery platform itself. Native pipeline integration adds plan approval, state management, drift detection, policy enforcement, and verification to Terraform workflows.
The combination removes manual handoffs, provides full audit trails, cost visibility, and security policy approval before production. It delivers control without friction by letting Terraform keep cloud definitions clean and portable while Harness automates the automation itself with continuous delivery discipline.
Organizations adopting this pairing gain repeatable IaC workflows with governance baked in, automated rollbacks when verification fails, and a fully codified delivery pipeline that is reproducible, auditable, and scalable.
Sources
- https://developer.harness.io/docs/platform/automation/terraform/harness-terraform-provider-overview/
- https://oneuptime.com/blog/post/2026-02-23-how-to-use-terraform-with-harness-for-cicd/view
- https://hoop.dev/blog/the-simplest-way-to-make-harness-terraform-work-like-it-should
- https://github.com/harness/terraform-provider-harness
- https://github.com/harness-community/terraform-harness-structure