> 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

Open a pull request from a cost or drift finding. You review and merge it.

From a cost or drift finding on the [Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) tab, the Remediation Agent opens a pull request with the proposed change. You review and merge it, then provision the workspace. The agent does not merge the pull request or change your infrastructure.

For a drift insight, the pull request updates your OpenTofu or Terraform configuration to match the current cloud state. The agent adopts the drifted value into your code and does not revert the resource. If you want the resource to return to what your configuration declares, do not merge the pull request, and provision the workspace instead.

Drift insights and remediation pull requests are not limited to AWS or Azure. Harness records a drift insight for each resource a drift run reports as changed or deleted, for the provider on that resource, and the Remediation Agent can open a pull request for that insight. Cloud Cost Management is a separate path: it syncs cost and recommendations for AWS, Azure, and Google Cloud resources, and the insight detail view has curated fields for AWS and Azure recommendation shapes.

***

## 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 Management Agent integration](/infrastructure-as-code-management/platform/workspaces/cloud-cost-management-integration.md) to enable Cloud Cost Management Integration.
* **A default remediation pipeline:** On the Insights tab, select **Setup Drift detection pipeline**. Harness opens **IaCM Defaults** on the **AI Remediation Agent** section. Turn on **Enable AI Remediation for this project** and select **Enable**. Harness creates a pipeline named **IACM Remediation** with one Remediation Agent step and sets it as the project default. The step takes the workspace and the insight ID when you run it. You can assign a different pipeline on that page after remediation is enabled. Go to [Default pipelines](/infrastructure-as-code-management/platform/iacm-pipelines/default-pipelines.md) to review the remediation default.
* **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.

{% hint style="warning" %}
**Review before you merge**

The pull request writes the current cloud state into your configuration, so merging it makes the drifted value your declared value. Review attributes that affect security, such as network source ranges, access rules, and encryption settings, before you merge.
{% endhint %}

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>

Cost findings use the same **Apply with agent** steps as drift. A cost pull request proposes the recommendation, for example rightsizing an instance. Go to [Cost Management Agent integration](/infrastructure-as-code-management/platform/workspaces/cloud-cost-management-integration.md) to turn the findings on, and go to [Workspace Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) for the supported resource types.

***

## 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>

Confirm a default remediation pipeline is configured for the project in the IaCM Defaults, and that the workspace is not excluded from remediation. If the button is still missing, contact Harness Support.

</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>

* Go to [Insights](/infrastructure-as-code-management/platform/workspaces/insights.md) to pick a finding and start **Apply with agent**.
* 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 Management Agent integration](/infrastructure-as-code-management/platform/workspaces/cloud-cost-management-integration.md) to turn on cost findings.

{% @harness-feedback/feedback %}
