For the complete documentation index, see llms.txt. This page is also available as Markdown.

Automate onboarding with Harness

Automate the provisioning of resources to Harness via the Harness Terraform Provider.

Harness offers a first-class Terraform Provider to automate adoption and growth.

To use the Harness Terraform Provider, go to Harness' Terraform module in the HashiCorp Terraform Registry. Select Next Gen to see all the resources Harness supports for provisioning.

This topic uses a sample repository to explain the steps to automate onboarding using the Harness Terraform Provider.

Important

  • To get started with the Harness provider, Harness recommends installing a delegate with Terraform CLI. You need the delegate to build out the automation pipelines to create the various resources.

  • Harness recommends making changes using Git when using the Terraform Provider.

  • Defining your resources like service, environment, infrastructure definition, etc. via Terraform is a one-way sync. By using Terraform, you define the object in Git. After you commit the change, a Harness pipeline provisions the resource to your account.

  • Any changes you make via Git are propagated to the UI via this pipeline, which fetches the Terraform file definition for the resource.

  • To avoid configuration mismatches, any changes you make in the UI must be reconciled and updated in the YAML.

  • To prevent the editing and creation of resources in the Harness UI, use RBAC.

Product Demo

Install a delegate

  1. Install a Kubernetes delegate. For steps to install a Kubernetes delegate, go to install delegate.

  2. Download the YAML.

  3. Modify the INIT_SCRIPT section in the YAML to include the following value:

YAML sample
  1. After you modify the delegate YAML, connect to the Kubernetes cluster to install. To do this, run the following command:

  2. Run the following command to verify if the Terraform CLI is successfully installed:

    To see if the CLI is installed successfully, search Terraform.

Set up a GitHub repo

  1. You can use an existing repo to manage the Harness configuration or create a new one. For more information on creating a GitHub Repo, go to Adding a local repository to GitHub using Git.

    Harness recommends creating a GitHub Repo to store and manage the Harness configuration.

  2. Harness recommends the following folder structure to manage your configurations:

Manage the automation pipeline

Harness recommends storing the automation pipeline to create and manage resources in a common project that many teams can access. You can create a project called Onboarding and users can leverage this to run the pipeline to create a service, environment, infrastructure definition, secret, etc. Harness lets you manage pipelines in Git via the Git experience. This lets you maintain all your pipeline configurations in Git.

Alternatively you can create pipeline templates that teams can use in their projects. This lets a central team manage the onboarding processes and distribute them to the application teams to leverage and onboard.

Set up pipeline

This section explains the steps to set up a sample pipeline.

  1. Create a pipeline.

  2. Create a trigger for a Git based source.

  3. Create the terraform resource file of a Harness object.

  4. Commit the Harness terraform resource object (service, environment, infrastructure, etc.) in GitHub.

  5. Watch the pipeline execute based on the trigger.

  6. In your Harness account, look for the resource that was configured to be created.

Build the pipeline

For detailed steps to build the pipeline, go to Kubernetes deployment tutorial.

Configure pipeline stages

To configure the stages for your pipeline, go to the following:

The Terraform Plan step fetches the terraform resource from Git. Harness then initiates a terraform plan on the files collected.

Harness passes the terraform plan that was generated based on the Harness Terraform resource file and then to the Terraform Apply step. The Terraform Apply step can inherit the plan and create or update the service resource by selecting Inherit from Plan.

Set up trigger

This section explains the steps to set up a sample trigger.

Harness recommends using the GitHub Webhook trigger because you can make changes in GitHub and based of a branch condition, push, pull request, issue comment, etc. you can fire off the pipeline to make changes. The trigger doesn't need to be GitHub.

Harness supports the following:

  • GitHub

  • GitLab

  • Bitbucket

For more information on triggers, go to Trigger pipelines using Git Events.

Onboard a service

For onboarding a Service onto Harness you will need to use the Harness Terraform Resource. In Harness, you can create a service at the project, organization or account level.

Your will need to create this YAML and store it in your Github Repository.

When you run an automation pipeline to create service, you will see the service created in the UI.

Set up pipeline for Service Creation

Here is a sample pipeline to create the nginx service and manage it via Git automation.

You also need to configure a Github Webhook Trigger to initiate updates to the service and automate the pipeline execution to update and create services.

The pipeline looks like this:

Onboard an environment

For onboarding an environment, Harness recommends using the environment resource in the Harness Terraform Provider. In Harness, you can create an environment at the project, organization, and account scope.

Your need to create this YAML and store it in your GitHub Repository.

When you run an automation pipeline to create environments, you will see the environment created in the UI:

Set up pipeline to onboard environments

Onboard an infrastructure definition

For onboarding an Environment, we recommend using the infrastructure definition in our Harness Terraform Provider. In Harness, you can create an Infrastructure Definition at the project, organization and account scope.

Infrastructure Definitions are associated with the environment, so you will need to create an environment before creating the infrastructure definition.

When you run your automation pipeline and apply the terraform for the infrastructure definition you will see it appear in the UI:

Set up pipeline to onboard infrastructure definitions

Best practices

We recommend starting out in the Harness User Interface to get familiar with all the constructions. Once you understand the relationships and the hierarchy you can then begin to automate the creation and management of these resources.

Review these topics to get familiar with the Harness constructs:

For best results, follow Terraform and CI/CD best practices, including:

  • Source control: Store Terraform configurations in a version control system such as Git to track changes and support collaboration.

  • Automated plan and apply: Use CI/CD pipelines to automate terraform plan and terraform apply. For example, you can use Harness CD pipelines to automate onboarding and service configuration.

  • State management: Use a remote backend, such as Terraform Cloud or AWS S3 with state locking, to maintain consistent state across teams and environments.

  • Notifications: Configure notifications for Terraform actions so failures during terraform apply are reported through channels such as Slack or email.

  • Monitoring and logging: Monitor infrastructure using tools like Grafana or Prometheus, and log changes and activities to support auditing and troubleshooting.

  • Secrets management: Secure sensitive data, such as API keys, using a secrets manager like HashiCorp Vault or AWS Secrets Manager.

  • Backups: Regularly back up Terraform state files to protect against data loss.

  • Documentation: Maintain clear documentation for Terraform configurations and modules, including design decisions and usage instructions, to ensure maintainability and team alignment.

Create a project for resource automation

We recommend two approaches:

  1. Creating a centralized project that you can give your end user developers access to onboard their own services and resources

  2. Create 1 Project that has a centralized platform team manage and onboard the app team services, environments and other configurations.

You should get started by creating a centralized project like this:

You can also create this via the Terraform Provider and manage it via the Terraform Provider in code

To manage the organization and project identifiers in code, we recommend user's creating a tfvars file to manage these resources. The tfvars file will act as a record of all the organizations and projects you created via terraform and can be the parameter file for onboarding automation.

Get the delegate operationalized

Tooling you should install:

  • kubectl

  • helm

  • terraform

These options are all available in the Harness Docs

Create the connectors and secrets first

Make sure the connectors are created in Harness. You can create them and manage them via the Terraform Provider or in the UI.

Connector

Below is a sample snippet for creating a connector via the Terraform Provider:

These connectors will require secrets to be configured because connectors are access objects that provide the Harness Delegate access to a particular resource. You can create the connectors via the Terraform Provider or in the Harness UI.

Secret

Below is a sample snippet for creating a secret text via the Terraform Provider:

Last updated

Was this helpful?