> 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/platform/workspaces/remediation-agent.md).

# IaCM Remediation Agent

Use the IaCM Remediation Agent to generate pull requests that propose fixes for drift insights and CCM cost optimization recommendations.

{% hint style="info" %}
This feature is in Beta[^1] and requires enablement. [View all early access features.](/release-notes/features.md)

{% @harness-feature-flag-access/request-feature-flag-access module="infrastructure-as-code-management" pagePath="infrastructure-as-code-management/platform/workspaces/remediation-agent" featureFlags="%5B%7B%22name%22%3A%22IaCM%20Remediation%20Agent%22%2C%22key%22%3A%22IACM\_REMEDIATION\_AGENT%22%2C%22status%22%3A%22BETA%22%2C%22description%22%3A%22Enables%20the%20IaCM%20Remediation%20Agent%20and%20the%20workspace%20Insights%20tab%20drift%20card.%20When%20a%20workspace%20resource%20drifts%2C%20you%20can%20trigger%20the%20agent%20from%20the%20Insights%20tab%20to%20generate%20a%20pull%20request%20that%20reconciles%20your%20Terraform%20or%20OpenTofu%20code%20with%20the%20actual%20cloud%20state.%22%7D%5D" %}
{% endhint %}

Harness IaCM lets you act on workspace insights directly from the [Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) tab. The Remediation Agent handles two types of insight: **drift** and **cost optimization recommendations**. For drift, it analyzes the gap between your OpenTofu or Terraform configuration and the actual cloud state, then generates a pull request with the configuration changes needed to close that gap. For cost recommendations sourced from Cloud Cost Management, it generates a pull request with the configuration changes needed to implement the recommendation. For example, rightsizing a cloud instance or shutting down an idle resource.

**The agent does not change your infrastructure directly.** It generates a pull request so you can review the proposed changes before merging. You merge the pull request and then provision the workspace to apply the change. This keeps your Git repository the source of truth and gives you a full review gate before any infrastructure changes take effect.

***

## How remediation works <a href="#how-remediation-works" id="how-remediation-works"></a>

Remediation runs on the project's default remediation pipeline. You configure this pipeline once for the project in the IaCM Defaults, and it then applies to every workspace in the project. Harness does not remediate insights automatically; you start each remediation from the Insights tab. The flow is the same whether you are acting on a drift insight or a cost recommendation:

1. Harness IaCM surfaces an insight on the workspace Insights tab: either a drift detection or a CCM cost recommendation.
2. You click **Apply with agent** on the insight.
3. Harness opens the **Run Pipeline** panel. Confirm the workspace and click **Run Pipeline**.
4. The remediation pipeline runs a single Remediation Agent step.
5. The agent generates a pull request with the proposed IaC changes for the affected resource.
6. The insight moves from **Open** to **Applied**. Applied means the pull request has been generated. Your infrastructure has not changed yet.
7. You review and merge the pull request, then provision the workspace to apply the change to your infrastructure.

***

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Before you launch remediation, confirm the following are in place:

* **A workspace with an open insight:** Insights appear on the Insights tab. Drift insights require drift detection to be configured. Cost optimization insights require Cloud Cost Management Integration to be enabled on the workspace. Go to [Drift detection](/infrastructure-as-code-management/platform/iacm-pipelines/operations-overview.md) to configure drift detection, and go to [Cost estimation](/infrastructure-as-code-management/platform/workspaces/cost-estimation.md) to enable Cloud Cost Management Integration.
* **A default remediation pipeline:** Configure the remediation pipeline for the project in the IaCM Defaults. Go to [Default pipelines](/infrastructure-as-code-management/platform/iacm-pipelines/default-pipelines.md) to review how defaults are configured.
* **Permission to run the pipeline and merge the pull request:** Execute permission on the remediation pipeline and write access to the connected repository. Go to [Workspace RBAC](/infrastructure-as-code-management/platform/workspaces/workspace-rbac.md) to review IaCM permissions.

***

## Remediate an insight <a href="#remediate-an-insight" id="remediate-an-insight"></a>

Once an insight appears on the Insights tab, you remediate it in a few steps.

1. Navigate to your workspace and select the **Insights** tab.
2. Locate the open insight you want to remediate, then click **Apply with agent**.

   ![Apply with agent button on a drifted resource](https://3575326923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ffhx6XzjvtJmfv5gPWZ5m%2Fuploads%2Fgit-blob-a5b38f7a354e81cfa41e5761a00126dd22a2b027%2Fapply-with-agent-drift.png?alt=media)
3. In the **Run Pipeline** panel, confirm the workspace, then click **Run Pipeline**.

   ![Run Pipeline panel for the remediation agent](https://3575326923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ffhx6XzjvtJmfv5gPWZ5m%2Fuploads%2Fgit-blob-68572f2b9a6d300a65f8642dcc164665305900db%2Fremediation-run-pipeline.png?alt=media)
4. When the pipeline completes, the insight moves to **Applied** and the execution output shows a link to the pull request. Open the pull request link.
5. Review the proposed changes in your repository, then merge the pull request and provision the workspace to apply the change to your infrastructure.

The Applied view shows the date and user who triggered the run, the estimated monthly savings (for cost recommendations), a **SUCCESS** or **FAILED** status, and links to the execution details and the pull request.

If the pipeline fails, the Applied view shows **Pipeline failed. Try to apply again**. Click **Apply with agent** again to re-run the remediation pipeline for that resource.

***

## Cloud Cost Management recommendations <a href="#cloud-cost-management-recommendations" id="cloud-cost-management-recommendations"></a>

When Cloud Cost Management is connected to a workspace, the Insights tab also surfaces cost optimization recommendations sourced from Harness CCM, for example rightsizing an oversized EC2 instance or shutting down an idle Azure VM. The **Apply with agent** flow for cost recommendations is identical to the drift flow: clicking the button runs the project's default remediation pipeline, which generates a pull request with the recommended configuration change.

CCM cost recommendations are supported for AWS and Azure resources. GCP recommendations are not supported at this time. Go to [Workspace Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) for the full list of supported resource types and recommendation actions.

To connect Cloud Cost Management to a workspace, go to [Cost estimation](/infrastructure-as-code-management/platform/workspaces/cost-estimation.md) and enable the **Cloud Cost Management Integration** toggle in the workspace configuration.

***

## Troubleshoot remediation <a href="#troubleshoot-remediation" id="troubleshoot-remediation"></a>

If remediation does not behave as expected, the following cases cover the most common causes.

<details>

<summary>The Apply with agent button is missing from an insight in Harness IaCM</summary>

The IaCM Remediation Agent is a beta feature that requires enablement. Contact Harness Support to request access, and confirm a default remediation pipeline is configured for the project in the IaCM Defaults.

</details>

<details>

<summary>The IaCM remediation pipeline finished but no pull request was created</summary>

Open the Remediation Agent step logs in the execution output. If the agent found no changes to recommend for the affected resource, it does not generate a pull request.

</details>

<details>

<summary>The IaCM remediation pull request contains more changes than expected</summary>

When Cloud Cost Management is connected to the workspace, the agent can include both drift fixes and CCM cost recommendations for the same resource in a single pull request. Review the diff before merging. If you want the pull request to cover drift only, disable the Cloud Cost Management Integration in the workspace Configuration tab.

</details>

***

## Next steps <a href="#next-steps" id="next-steps"></a>

With remediation configured, you can act on insights as soon as they surface.

* Go to [Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) to review the insights you can remediate and the supported CCM recommendation types.
* Go to [Drift detection](/infrastructure-as-code-management/platform/iacm-pipelines/operations-overview.md) to understand how Harness IaCM detects drift.
* Go to [Default pipelines](/infrastructure-as-code-management/platform/iacm-pipelines/default-pipelines.md) to configure the remediation pipeline for your project.
* Go to [Cost estimation](/infrastructure-as-code-management/platform/workspaces/cost-estimation.md) to connect Cloud Cost Management to your workspace.

{% @harness-feedback/feedback %}

[^1]: Beta features are feature-complete but still being validated. Available on request.
