Infrastructure Definitions

Updated 1 week ago by Michael Cretzman

This topic discusses Harness Infrastructure Definitions, which are part of a Harness Environment.

In this topic:

Infrastructure Definition Overview

Infrastructure Definition replaces Service Infrastructure as the method for defining your target infrastructure. Currently, Infrastructure Definition is behind a feature flag. Contact Harness Support to migrate to Infrastructure Definitions.

The Infrastructure Definition is where you specify the target infrastructure for your deployment. The target infrastructure can be an existing infrastructure or an infrastructure provisioner, such as Terraform or CloudFormation, set up as a Harness Infrastructure Provisioner.

When you create a Harness Workflow, you pick the Infrastructure Definition you want to use as the target deployment environment.

Add an Infrastructure Definition

To add an Infrastructure Definition, do the following:

  1. In your Harness Application, open or create an Environment.
  2. In the Environment, you can see the Infrastructure Definition section.

  1. Click Add Infrastructure Definition. The Infrastructure Definition dialog appears.

  1. In Name, enter the name that will identify this Infrastructure Definition.
  2. In Cloud Provider Type, select the type of Cloud Provider for Harness to use when connecting to the target infrastructure you will define. For example, if the target infrastructure is in AWS, select Amazon Web Services.

    Which Type do I Use? Pick the same type of Cloud Provider as the Cloud Provider you want this Infrastructure Definition to use to connect to your target infrastructure.
  3. In Deployment Type, select the type of deployment that matches the target infrastructure type. For example, if you are defining an infrastructure for AWS Lambda, then your Deployment Type would be AWS Lambda. If you are defining a Kubernetes cluster, then the Deployment Type would be Kubernetes.

That's the initial configuration of the Infrastructure Definition. The remaining settings depend on the Cloud Provider Type and Deployment Type you selected. If you selected AWS-related types, the remaining settings are AWS-related. If you select Kubernetes-related types, you will have Kubernetes cluster settings to provide.

Scope to Specific Services

The Scope to specific Services setting in the Infrastructure Definition enables you to scope this Infrastructure Definition to specific Harness Services.

This enables you to create one Infrastructure Definition and apply it to multiple Services. This will make the Infrastructure Definition available whenever a Workflow (or Phase) is set up for one of the Services.

For example, here is an Infrastructure Definition named Lambda-QA scoped to the Service named AWS Lambda. Next is a Workflow where the AWS Lambda Service has been selected.

You can see that since the AWS Lambda Service was selected in the Workflow setup, the Infrastructure Definition Lambda-QA is available in the Infrastructure Definition setting.

This is because the Lambda-QA Infrastructure Definition is scoped to the AWS Lambda Service.

If you create an Infrastructure Definition but do not add a Service using the Scope to specific Services setting, the Infrastructure Definition is available to all Workflows for Services that are of the same type as the Infrastructure Definition Deployment Type. When a Workflow is deployed, the Service deployed by the Workflow is added to the the Scope to specific Services setting in the Infrastructure Definition.

When creating Infrastructure Definitions, you might want to simply leave the Scope to specific Services setting empty until you have set up the Services you want to deploy to the Infrastructure Definition, and then enter the Services in the Scope to specific Services setting.

Unscoped Infrastructure Definitions

When you do not select the Scope to specific Services setting, the Infrastructure Definition is not scoped to specific Service(s), and therefore it can be used with any Services.

When you create a Workflow, any unscoped Infrastructure Definitions (where the Scope to specific Services setting is not selected) are available. The Infrastructure Definitions that appear in the Workflow are still dependent on the type of Service you select in the Workflow settings.

In the following example, the Infrastructure Definition is not scoped to a Service. The Workflow Phase setup dialog allows the Infrastructure Definition to be selected because both the Infrastructure Definition Deployment Type and the Service selected in the Workflow Phase setup are Kubernetes types.

When the Workflow is deployed, the Service is automatically added to the Service Infrastructure Mapping of the Infrastructure Definition, regardless of whether the deployment was successful:

When additional Workflows use the Infrastructure Definition and deploy, they will be automatically added to the Service Infrastructure Mapping of the Infrastructure Definition also. Their deployment status is also listed:

Using Expressions in Infrastructure Definitions

You can use expressions for many Infrastructure Definition settings. This enables you to use a single Infrastructure Definition in multiple Workflows. In each Workflow, you can replace the expression with a specific value.

For example, here is the Infrastructure Definition for a Kubernetes cluster. In the Namespace field we have the expression ${workflow.variables.namespace}:

In each Workflow that uses this Infrastructure Definition, you can add a Workflow variable that replaces the namespace expression with a hardcoded value:

You could also have a non-fixed Workflow variable, and have the value entered during deployment manually...

...or you can have the value passed in by a Trigger.

Service Variables

Currently, Service variables cannot be automatically filled in Infrastructure Definition fields. Typically, automatically-filled Service variables appear when you begin typing ${ in a field. Until they are supported, you can enter them manually by typing ${serviceVariable.var_name} where var_name is the Service variable name.

If an Infrastructure Definition is scoped to specific Services, only use Service variables from those Services.

If an Infrastructure Definition is not scoped, and therefore available to any Service of the same type, you can use Service variables from any Service of the same type.

How did we do?