Get Started With Terraform
Create a Terraform workspace and provision infrastructure with Harness IaCM.
Use this guide to create a Terraform workspace. Provision infrastructure through Harness Infrastructure as Code Management (IaCM).
What is IaCM?
IaC automates infrastructure management via code. IaCM enhances this by ensuring consistent, accountable, and repeatable deployments. Harness boosts IaCM with real-time cost estimation, automated policy enforcement, and drift detection, ensuring efficient provisioning and compliance with standards.
Go to What's Supported in IaCM for more information on supported Cloud Providers and Code/Git providers.
Terraform is a widely used infrastructure-as-code tool. Harness Infrastructure as Code Management (IaCM) runs MPL-licensed Terraform versions in workspaces and pipelines, with Git-backed configuration, connectors, and optional cost estimation.
This guide walks you from connectors and workspace creation through a standard provision pipeline (init, plan, apply) and an optional approval between plan and apply.
What you will learn from this topic
This guide covers the following:
Connectors and workspace: Create cloud and Git connectors, then create a Terraform workspace wired to your repository and Terraform version.
Provision pipeline: Generate or author a pipeline that runs init, plan, and apply for your workspace.
Approvals: Optionally gate apply behind an approval step.
Before you begin
Before you use this guide, ensure you have the following:
Harness account with IaCM enabled: You need Infrastructure as Code Management under Infrastructure in Harness when it is entitled on your account. Go to Getting started with Harness Platform to access or create a Harness account.
Pipeline permissions: View, Create/Edit, and Execute on Pipelines. Go to RBAC in Harness to review the permissions model, and go to Manage roles to assign a role that includes them.
Git repository: Access to a Git provider with your Terraform project.
Cloud provider: Access to a cloud provider such as AWS or Google Cloud Platform for the infrastructure you manage.
Harness organization and project: An organization and project set up on the Harness Platform.
Set up your workspace
A workspace is a named environment for storing your Terraform configurations and resources. Connect your Cloud Provider and Code Repository through Connectors to manage infrastructure changes and updates with Harness IaCM pipelines.
Step 1: add connectors
Use Harness AI to create and configure your cloud provider and code repository connectors before you create a workspace:
When adding any connector, start by:
Sign in to app.harness.io.
In the module pane, select Infrastructure.
Select Project Setup, and then select Connectors.
Select New Connector (AI).
Select an option, for example "Create a GitHub connector", or type your request to create a connector for your chosen cloud provider or code repository.
Harness creates a YAML file for your connector. Once you select Create, Harness creates your connector and adds it to your project.
Go to Connect your Cloud Provider and Connect your Code Repository to connect your cloud provider and code repository.
Step 2: create your workspace
Once you have configured your connectors, you can create a workspace and select them in the New Workspace panel:
In the module pane, select Infrastructure.
Select an existing project or create a new project.
Select Workspaces, and then select New Workspace.
Select Create new Workspace, then select Start from scratch and complete the following fields in the new workspace wizard:
About workspace
Name - Enter a unique name to identify the workspace.
Description (optional): Enter an optional description to help identify the workspace.
Tags (optional): Add a unique tag to identify the workspace.
Configure repository details
Select your Git provider, either Harness Code Repository or Third-party Git provider for other providers like GitHub or GitLab.
Git Connector: Select the Git connector you created in the previous step.
Git Fetch Type: Select the Git fetch type, either Latest from branch, Git tag or Commit SHA.
Git Branch: Specify the branch you want to use for the workspace.
Folder Path: Specify the folder path to the Terraform configuration files in the repository.
Advanced options allow you to include submodules if your code repository includes modules and submodules. Go to Module Registry to review module registry concepts.
Provisioner
Connector: Select the cloud provider connector you created in the previous step.
Cloud Cost Estimation: Toggle the Enable Cost Estimation switch to enable cloud cost estimation. This lets you estimate the cost of your infrastructure changes before you apply them.
Workspace Type: Select Terraform as the workspace type you want to use for the workspace.
Terraform Version: Select the Terraform version you want to use for the workspace, up to version 1.5.x (MPL licenses).
Add variable set (optional)
If you have configured variable sets for reuse, select the variable set you want to use for the workspace.
Select Create.
Step 3: add a provision pipeline
A pipeline structures workflows to manage tasks like planning infrastructure changes, enforcing policies, and approvals. Go to Harness Pipelines to review pipeline concepts. You can also add pipelines through the Harness Platform or use a code-first approach with YAML.
Harness AI pipeline generation
Start by adding the pipeline:
Select the Infrastructure module.
Select Pipelines, then select Create a Pipeline.
Select an option from Harness AI chat or type a request to generate one, for example:
"Create a pipeline to Provision a Terraform files with an init, plan and apply step."
Review the generated YAML and Harness AI chat summary, and make any changes if necessary.
Select Accept.
The Provision operation adds three Terraform plugin steps: init, plan, and apply. Go to Tofu/Terraform Plugins to review supported OpenTofu/Terraform commands.
Step 4: add an approval step (optional)
You can add the Approval step to prompt a review of the previous pipeline stage before proceeding. The most common use case is to add the Approval step between the plan and apply steps so you can review infrastructure changes and estimated costs (if cost estimation is enabled on your workspace) before applying them.
APPROVAL STEPS HOLD RESOURCES
When using an Approval step, the underlying machine running the pipeline remains active until the approval is resolved. This means it will continue consuming compute resources.
From the Pipeline > Execution tab, click the Add icon between
planandapply.

Click Add Step.
Under IACM, select IACM Approval.
Name the approval step and click Apply Changes.
Click Save, then click Run to run your pipeline.
Next steps
This guide introduced you to the core functionalities and setup of Harness IaCM, from creating workspaces to configuring pipelines. To enhance your experience and team efficiency, get the most out of Harness IaCM's built-in reusable features, including:
Workspace Templates: Quickly create new workspaces using pre-defined, customizable templates.
Module Registry: Share and reuse infrastructure modules across teams to standardize deployments.
Default Pipelines: Start with ready-made pipeline templates to accelerate automation and best practices.
Queue Step: Serialize your pipeline execution to track concurrent executions and prevent state conflicts.
Harness CLI: Install the unified CLI to list, get, and execute IaCM workspaces from your terminal.
Go to Harness AI Chat use cases for more use cases on Harness AI, and platform integration.
For an interactive onboarding experience including further use cases and features like **drift detection**, **remote backends**, and **policy enforcement**, check out Harness IaCM self-paced training.
Last updated
Was this helpful?
