SLO as code
Harness provides tools such as Git Experience 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.
- 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
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.
For detailed instructions on how to prepare files required for Terraform setup, go to Harness Provider on Terraform.
Set up a Terraform compliant delegate
Set up Harness Delegate to run the Terraform setup for appling the changes.
In your Harness Delegate, run the following commands to install the libraries required for Terraform:
apt-get install wget
apt-get -y install git
apt-get install unzip
cp terraform /usr/bin/
Create a pipeline and add Terraform Plan step
To create a pipeline:
- In Harness, go to your project > Deployment > Pipelines, and then select + Create a Pipeline.
- Add a custom stage.
- Select Add Step and choose Terraform Plan.
- Enter a name for the Terraform Plan
- Enter a name for the Provisioner Identifier and add a Secret. You will be asked for this secret when applying the Terraform Plan step.
- 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.
Add Terraform Apply step
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
To learn how to create a webhook trigger, go to Trigger Deployments using Custom Triggers.
Add a webhook to the GitHub repository
To add a webhook URL to a GitHub repository:
- In your GitHub repository go to settings > webhooks.
- Add a new webhook and paste the payload URL from that you copied in step 1.
- Paste the secret created while setting up the trigger.
- Select the event as Just the push event to trigger the webhook.
- Save the webhook.
Push changes to the repository
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.