Control Resource Usage

Updated 2 months ago by Michael Cretzman

To queue the number of resources Harness requests during a deployment, and prevent multiple Workflows requesting the same deployment environment resources at the same time, you can place capacity limits on the resources Harness requests.

For example, a deployment cloud environment (AWS, GCP, Azure, etc) might limit host access to 5 at a time. You can use Resource Constraints to ensure that the Workflow only requests access to 5 at the same time during deployment.

Another common example is deploying multiple artifacts to a single Kubernetes namespace because the same Workflow is deployed by two people simultaneously. To avoid collision, and queue deployments, you can set a maximum capacity of one request to the namespace at a time.

Resource Constraints are Account-wide. This ensures that if a Resource Constraint is placed in one Workflow, it will restrict any other Workflow in the Account from using the resource until it is safe to use.

In this topic:

Control Resource Usage

Resource Constraints are set up at the Harness Account level, and may be used throughout all Applications.

To create a Resource Constraint, do the following:

  1. In Harness, click Setup.
  2. In Account, click the vertical ellipsis, and then click Resource Constraints.

The Resource Constraints dialog appears.

  1. Click Add Constraint.
  2. Fill out the constraint fields:
  • Resource Constraint - Enter a name for your resource constraint. You will use this name to select the Resource Constraint in a Workflow.
  • Capacity - The maximum number of resources that may be consumed simultaneously.
  • Strategy - Choose FIFO if you want the resource requests to be selected in the order they arrived. Choose ASAP if you want Harness to select the first pending resource request that matches the number of available resources.
    As an ASAP example, imagine you have two resource requests: the first needs 2 hosts, and the second request needs 1 host. When 1 host becomes available, the second request is given the host as its request matches the number of available resources first.

The Current Usage value identifies if the resource restriction is applied a Workflow.

Apply Constraints in Workflows

You can use your Resource Constraints anywhere they are needed in a Workflow to queue resource requests.

Only add Resource Constraints to Workflow sections where the resource you reference can be obtained. For example, if you add Resource Constraints to the Pre-deployment Steps. then Services and Infrastructure Definition cannot be referenced as Harness has not selected those at this stage of the Workflow.

To apply a Resource Constraints to a Workflow, do the following:

  1. In a Workflow, click Add Step. The Resource Constraint dialog appears.
  2. Fill out the constraint settings and click SUBMIT. The settings are described below.

Resource Constraint ID

Select the Resource Constraint to use at this stage of the Workflow. Note the capacity of the restriction. This is the maximum number of resources that may be consumed simultaneously.

Required Resource Usage

Enter the number of resources that are required at this step in the Workflow. If the number is more than the Capacity of the Resource Constraint you selected, the Workflow will remain at this step until the required resource usage has been reached. This is how you queue resource usage.

For example, if the Capacity is 4 and the Required Resource Usage is 5, Harness will use 4 resources simultaneously and wait until 1 resource becomes free so that it can use it for the 5th required resource.


The resource unit is any value that can identify a resource uniquely. You can use Harness built-in variables by entering $ and selecting from the list.

For example, to queue the services deployed to a Kubernetes namespace, you can enter ${infra.kubernetes.namespace} in Unit and set the Resource Restraint Capacity to 1.

To queue the services deployed to a particular Harness Infrastructure Definition that uses the namespace, you would enter ${infra.kubernetes.infraId}-${infra.kubernetes.namespace} in Unit.

The following image shows the Resource Constraint step in the Workflow with Unit set to ${infra.kubernetes.infraId}-${infra.kubernetes.namespace} and the results of the deployed Workflow:


Scope this constraint to this Workflow.


Enter how long the Resource Constraint should run before failing the step. If the timeout is reached before the Resource Constraint is able to process all resource requests, it will fail the Workflow and rollback will occur.

How did we do?