> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/provisioners/terragrunt-get-started.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Terragrunt: Get Started

Create a Terragrunt workspace in Harness IaCM, choose Terragrunt and OpenTofu or Terraform versions, and override the folder path for each pipeline run

Create a Terragrunt workspace in Harness Infrastructure as Code Management (IaCM) and provision infrastructure with a pipeline that runs `init`, `plan`, and `apply`. You can also override the workspace folder path on each pipeline step, which suits monorepos and multi-environment layouts.

In IaCM, Terragrunt extends OpenTofu or Terraform rather than replacing it. Terragrunt still runs their `plan` and `apply` commands, so you select the binary (OpenTofu or Terraform) and its version when you create the workspace.

***

## Before you begin

Make sure you have the following:

* **IaCM access:** **Infrastructure as Code Management** under **Infrastructure** in Harness, when it is entitled on your account. Go to [Getting started with Harness Platform](https://developer.harness.io/harness-platform/new-to-harness-platform/get-started.md) to access or create a Harness account.
* **Organization and project:** A Harness organization and project for the workspace. Go to [Getting started with Harness Platform](https://developer.harness.io/harness-platform/new-to-harness-platform/get-started.md#create-an-organization) to create them.
* **Workspace permissions:** **Create/Edit** on workspaces. Go to [Configure Workspace Permissions](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/govern/configure-workspace-permissions.md) to assign it.
* **Pipeline permissions:** **View**, **Create/Edit**, and **Execute** on pipelines. Go to the [permissions reference](https://developer.harness.io/harness-platform/3.0/harness-platform-resources/platform-access-control/permissions-reference.md#pipelines) to review them, and go to [Manage roles](https://developer.harness.io/harness-platform/3.0/harness-platform-resources/platform-access-control/add-manage-roles.md) to assign a role that includes them.
* **Git repository:** Access to a Git provider that holds your [Terragrunt](https://terragrunt.gruntwork.io/) project.
* **Cloud provider:** Access to a cloud provider, such as AWS or Google Cloud Platform, for the infrastructure you manage.

{% hint style="info" %}
**Contact Harness Support**

If IaCM does not appear, go to [What Is Harness IaCM?](https://developer.harness.io/infrastructure-as-code-management/3.0/start-here/get-started/what-is-harness-iacm.md), or contact your account administrator or [Harness Support](mailto:support@harness.io).
{% endhint %}

{% hint style="info" %}
**Terraform versions**

For the Terraform binary, IaCM supports MPL-licensed versions up to 1.5.x. Terraform 1.6 and later are not supported. Go to [What's Supported](https://developer.harness.io/infrastructure-as-code-management/3.0/start-here/get-started/whats-supported.md) to review supported versions.
{% endhint %}

***

### Create a workspace and provision it

Harness recommends that you create your connectors before you create the workspace, although you can also add connectors during workspace creation. The following steps take you from connectors to a provisioned Terragrunt workspace.

{% stepper %}
{% step %}

### Add connectors

Use Harness AI to create your cloud provider and code repository connectors.

1. Navigate to the **Infrastructure** module.
2. Select **Project Setup**, then select **Connectors**.
3. Click **New Connector (AI)**.
4. Select a suggested request, such as "Create a GitHub connector", or enter your own request for your cloud provider or code repository.
5. Review the generated connector YAML, then click **Create**.

To change a connector, edit the generated YAML, or click **Edit Details** in the connectors panel. For easier token management, use the **OIDC** (OpenID Connect) option in the **Credentials** panel, so the connector assumes a role you control in your cloud provider.
{% endstep %}

{% step %}

### Create the workspace

1. In the **Infrastructure** module, select an existing project or create a new one.
2. Select **Workspaces**, then click **New Workspace**.
3. Select **Create new Workspace**, then select **Start from scratch**.
4. In **About workspace**, enter a unique **Name**, and optionally a **Description** and **Tags**.
5. In **Configure repository details**, select **Harness Code Repository** or **Third-party Git provider**, then select your **Git Connector**.
6. Select the **Git Fetch Type**: **Latest from branch**, **Git tag**, or **Commit SHA**, then enter the **Git Branch**.
7. Enter the **Folder Path** from the repository root to the directory that holds your Terragrunt configuration. Pipeline steps use this path unless a step sets an override.
8. In **Provisioner**, select your cloud provider **Connector**, then select **Terragrunt** as the **Workspace Type**.
9. Select the **Terragrunt Version**.
10. Select the **Terragrunt TF Binary**, either OpenTofu or Terraform, then select its **Terragrunt TF Version**.
11. Optionally, turn on the option to run all Terragrunt modules.
12. Optionally, select a variable set, then click **Create**.

When you run all Terragrunt modules, Harness reviews your Terragrunt modules at the root level and in nested folders, and runs every detected module in a single workspace execution. Leave the option off to review only the root-level modules.
{% endstep %}

{% step %}

### Generate a provision pipeline

1. In the **Infrastructure** module, select **Pipelines**, then click **Create a Pipeline**.
2. In Harness AI chat, select a suggested request or enter one that asks for a pipeline with `init`, `plan`, and `apply` steps for your Terragrunt workspace.
3. Review the generated YAML and the Harness AI chat summary, and make any changes you need.
4. Click **Accept**.

The provision operation adds three plugin steps: `init`, `plan`, and `apply`. Go to [Create a pipeline](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/create-pipeline-quickstart.md) to author the pipeline in YAML instead.
{% endstep %}

{% step %}

### Add an approval step (optional)

Add an approval between `plan` and `apply` to review the infrastructure changes, and the estimated costs when cost estimation is on, before they apply.

1. On the pipeline **Execution** tab, click the **Add** icon between `plan` and `apply`.
2. Click **Add Step**.
3. Under **IACM**, select **IACM Approval**.
4. Name the approval step, then click **Apply Changes**.
5. Click **Save**, then click **Run**.
   {% endstep %}
   {% endstepper %}

When the run completes, the pipeline has run `init`, `plan`, and `apply` against your workspace, and the workspace status is **Active**.

{% hint style="warning" %}
**Approval steps hold compute resources**

While a pipeline waits at an approval step, the machine that runs the pipeline stays active and keeps consuming compute resources.
{% endhint %}

### Override the folder path for a run

Each Terragrunt `init`, `plan`, and `apply` step has an optional **Folder Path Override** in the pipeline editor, or the equivalent in YAML. Set it to point a single step at a different directory without changing the workspace.

To override the folder path, do the following:

1. Open the provision pipeline and select the Terragrunt `init` step.
2. In **Folder Path Override**, enter the path from the repository root to the directory that holds the Terragrunt configuration for this run.
3. Enter the same value on the `plan` and `apply` steps, so every step targets the same Terragrunt context.
4. Click **Save**, then click **Run**.

{% hint style="info" %}
**Folder path precedence**

A **Folder Path Override** on a Terragrunt step takes precedence over the workspace **Folder Path** for that step only. When the override is empty, the step uses the workspace **Folder Path**.
{% endhint %}

For a monorepo, set the workspace **Folder Path** to the repository root, so one workspace represents the whole Terragrunt repository. For each environment-specific run, such as `environments/dev` or `environments/prod`, set **Folder Path Override** to that subdirectory on `init`, `plan`, and `apply`. This replaces a separate workspace for each environment.

***

## Troubleshooting

<details>

<summary>A Terragrunt step runs against the wrong directory</summary>

A step uses its **Folder Path Override** when one is set, and the workspace **Folder Path** otherwise. Confirm that `init`, `plan`, and `apply` all carry the same override value, or that all three leave it empty.

</details>

<details>

<summary>Terragrunt modules in nested folders do not run</summary>

By default, the workspace reviews only root-level Terragrunt modules. Turn on the option to run all Terragrunt modules in the workspace provisioner settings, so Harness detects and runs modules in nested folders as part of one execution.

</details>

<details>

<summary>The Terraform version you need is not in the Terragrunt TF Version list</summary>

IaCM supports MPL-licensed Terraform versions up to 1.5.x. Terraform 1.6 and later are not supported. Select OpenTofu as the **Terragrunt TF Binary** to use later versions.

</details>

***

## Next steps

You created a Terragrunt workspace, provisioned it, and learned how to target a different directory for each run.

* Go to [Use Workspace Templates](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/set-up/use-workspace-templates.md) to create new workspaces from predefined templates.
* Go to [Use Default Pipelines](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/plan-and-apply/use-default-pipelines.md) to reuse ready-made pipelines for common operations.
* Go to [Serialize Runs with a Queue Step](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/plan-and-apply/serialize-runs-with-a-queue-step.md) to prevent state conflicts between concurrent runs.
* Go to [Migrate State into Harness](https://developer.harness.io/infrastructure-as-code-management/3.0/use-iacm/workspaces/manage-state/migrate-state-into-harness.md) to bring the state of an existing project into a workspace.

{% hint style="info" icon="diploma" %}
**Harness University: self-paced training**

Go to the [Harness IaCM self-paced training](https://university-registration.harness.io/self-paced-training-harness-infrastructure-as-code-management) to explore further use cases and features like **drift detection**, **remote backends**, and **policy enforcement**.
{% endhint %}

{% @harness-feedback/feedback %}
