Using Terraform to install GitOps agent
Using Terraform to install GitOps agent
This article prpvides a working example of how you can configure a Harness Gitops agent using Terraform.
Prerequisites
Before you start, ensure you have the following:
Terraform Installed: Download and install Terraform on your local machine.
Kubernetes Cluster: Access to a Kubernetes cluster (for example, Minikube, EKS, or GKE).
kubectl: The Kubernetes command-line tool to configure your cluster.
API Key: Your Harness API key for authentication.
You can follow the steps below to configure a Harness Gitops agent. Some steps required creating a file for which a working example is provided accordingly.
Step 1: Configure the Terraform Provider
To set up the Terraform provider for Harness, create a file named provider.tf.
terraform {
required_providers {
harness = {
source = "harness/harness"
version = "0.24.2"
}
}
}
provider "harness" {
endpoint = "https://app.harness.io/gateway"
account_id = var.account_id
platform_api_key = var.harness_api_key
}Step 2: Define Variables
Create a variables.tf file to define the necessary variables.
Step 3: Install the GitOps Agent
Define the GitOps agent resource in a new file named gitops_agent.tf.
The following fields are mandatory:
account_id (String): Account identifier of the GitOps agent.
identifier (String): Identifier of the GitOps agent.
name (String): Name of the GitOps agent.
type (String) Default: "MANAGED_ARGO_PROVIDER", Enum: "CONNECTED_ARGO_PROVIDER", "MANAGED_ARGO_PROVIDER"
The following fields are optional:
description (String): Description of the GitOps agent.
metadata (Block List, Max: 1): Metadata of the agent.
operator (String): The operator to use for the Harness GitOps agent. Enum: "ARGO" "FLAMINGO"
org_id (String): Organization identifier of the GitOps agent.
project_id (String): Project identifier of the GitOps agent.
tags (Map of String): Tags for the GitOps agents. You can use these to search or filter the GitOps agents.
You can find more details in the Harness Terraform Registry.
Step 4: Initialize Terraform
With your configurations ready, execute the following steps to initiate Terraform.
Step 5: Set values to variables
Set values to the variables required for your resources in a new file named terraform.tfvars
Change the variable values based on your environment.
Set the account_id and harness_api_token as Terraform environment variables. You can find your Account ID in the URL after the account/ once you log into app.harness.io.
Step 6: Apply Terraform
Preview the changes that Terraform makes in Harness and in your cluster.
Apply the Terraform configuration to create the Harness GitOps agent and the cluster resources. Type yes to confirm when prompted.
Observe the output of terraform apply command as your resources are created. It may take a few minutes for all the resources to be provisioned.
Verify GitOps deployment
Log into https://app.harness.io. Select Deployments->GitOps.
Select Settings on the top right corner of the page, and then select GitOps Agents.
Verify that your GitOps agent is listed.
Conclusion
In this article, you learnt how to create and configure a GitOps agent using Terraform provider with a hand-held example.
Last updated
Was this helpful?