> 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/service-reliability-management/use-srm/slo-types/slo-as-code.md).

# SLO as code

Harness provides tools such as [Git Experience](/harness-ai/use-harness-platform/git-experience/git-experience-overview.md) and Terraform, to help you manage entities using code.

Using the SLO as code feature of Harness SRM, you can manage Service Level Objectives (SLOs) through code. SRM supports SLO as code for Terraform based entities. This means that the definition of the entity is stored in GitHub using Terraform based files.

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* A Git repo with at least one branch.​
* A Git connector with a Personal Access Token (PAT) for your Git account.​

The following sections explain how to set up Terraform based entities to manage SLO as code.

### Set up a Git Repository in GitHub <a href="#set-up-a-git-repository-in-github" id="set-up-a-git-repository-in-github"></a>

Create a Git repository in GitHub. This repository must include a folder that contains all the necessary Terraform based files for creating a SLO. To see a sample folder that contains all the required entities in Terraform format, go to the [demo repository](https://github.com/deepakchhikara66/demo/tree/harness/harness/slo).

For detailed instructions on how to prepare files required for Terraform setup, go to [Harness Provider on Terraform](https://registry.terraform.io/providers/harness/harness/latest/docs).

### Set up a Terraform compliant delegate <a href="#set-up-a-terraform-compliant-delegate" id="set-up-a-terraform-compliant-delegate"></a>

Set up Harness Delegate to run the Terraform setup for applying the changes.

In your Harness Delegate, run the following commands to install the libraries required for Terraform:

```
set +x
apt-get update
apt-get install wget
apt-get -y install git
wget https://releases.hashicorp.com/terraform/1.3.6/terraform_1.3.6_linux_amd64.zip 
apt-get install unzip
unzip terraform_1.3.6_linux_amd64.zip
cp terraform /usr/bin/
terraform --version
```

### Create a pipeline and add Terraform Plan step <a href="#create-a-pipeline-and-add-terraform-plan-step" id="create-a-pipeline-and-add-terraform-plan-step"></a>

To create a pipeline:

1. In Harness, go to your project > **Deployment** > **Pipelines**, and then select **+ Create a Pipeline**.
2. Add a custom stage.
3. Select **Add Step** and choose **Terraform Plan**.
4. Enter a name for the Terraform Plan
5. Enter a name for the **Provisioner Identifier** and add a **Secret**. You will be asked for this secret when applying the Terraform Plan step.
6. In **Configuration File Repository**, select the GitHub repository that you created.
7. On the **Advanced** tab, select the delegate that you created as the default delegate for Terraform Plan.
8. Select **Apply Changes** to save and add the Terraform Plan step to the pipeline.

### Add Terraform Apply step <a href="#add-terraform-apply-step" id="add-terraform-apply-step"></a>

To add a Terraform Apply step: In the custom stage, select **Add Step** and choose **Terraform Apply**. Enter a name for the Terraform Apply step, select **Configuration Type**, and **Provisioner Identifier**. In **Configuration File Repository**, select the GitHub repository that you created. On the **Advanced** tab, select the delegate that you created as the default delegate for Terraform Plan. Select **Apply Changes** to save and add the Terraform Plan step to the pipeline.

### Create a webhook trigger <a href="#create-a-webhook-trigger" id="create-a-webhook-trigger"></a>

To learn how to create a webhook trigger, go to [Trigger pipelines using custom triggers](/harness-ai/use-harness-platform/triggers/trigger-deployments-using-custom-triggers.md).

### Add a webhook to the GitHub repository <a href="#add-a-webhook-to-the-github-repository" id="add-a-webhook-to-the-github-repository"></a>

To add a webhook URL to a GitHub repository:

1. In your GitHub repository go to settings > webhooks.
2. Add a new webhook and paste the payload URL from that you copied in step 1.
3. Paste the secret created while setting up the trigger.
4. Select the event as **Just the push event** to trigger the webhook.
5. Save the webhook.

### Push changes to the repository <a href="#push-changes-to-the-repository" id="push-changes-to-the-repository"></a>

Push your changes to the GitHub repository to trigger a workflow for the pipeline. During the pipeline run, the Terraform Plan step fetches changes from GitHub and applies them to all updated entities. The changes can be creating a new entity, updating an existing entity, or deleting an existing entity. During the pipeline run, the Terraform Plan step fetches the latest changes from the repository and generates a plan for updating the infrastructure. The plan may include creating a new entity, updating an existing entity, or deleting an existing entity.

![Push Terraform changes to repo](/files/KSaczFIs6ZKzqOYObv2C)

FEEDBACK\_BUTTON
