Dependent Resources

Resources that are depended on by a Workload are called Dependent Resources. They can either be Shared (available to all Workloads in an App) or Private (only available to a single Workload).

The outputs of a resource are defined by the type of the resource. These outputs can be referenced using placeholders from within the parts of the workload specification.

Dependent Resource IDs

Dependent resources must have a unique ID within their scope. For example, the workload workload-1 can have a dependency on a resource of type postgres with ID my-db and workload-2 could have a dependency on a resource of type mysql and also have an ID of my-db because they are in different scopes.

These IDs can be used in placeholders to reference the outputs of a resource once provisioned. To reference the name of the database created with the ID my-db in the workload, the following placeholder could be used:

${externals.my-db.name}

Shared Resource dependencies

Shared Resources Dependencies in Humanitec are dependencies on resources that are available to all Workloads in an Application. This can be useful in a variety of scenarios, such as when multiple Workloads need to access the same database, or when different Workloads need to respond to requests for a shared domain name.

To create a Shared Resource Dependency, you can use the Humanitec UI, CLI, or API. This allows you to specify the details of the resource, such as the type of resource (for example, database, domain name), the configuration and settings, and the access controls. Once the Shared Resource has been created, it will be available to all Workloads in the Application, so they can access and use it as needed.

Add shared Resource to an Application

  1. From the Application overview, select the name of the Application you’d like to add shared resources to.

  2. Select Shared resources and select the Add shared resource drop down and select a resource to add from the list.

  3. Enter a unique resource ID and select Done to create the shared resource.

You can view, edit, or delete the resource by selecting the corresponding options from the dropdown menu next to the resource.

humctl update delta ${DELTA_ID} add /shared/${RES_ID} '{ "type": "'${RES_TYPE}'" }'

Where the following environment variables are set:

Variable Example Description
DELTA_ID 612304986f51413 The ID of an existing, unarchieved delta.
RES_ID users-db The ID of the shared resource.
RES_TYPE postgres The resource type of the resource.

curl "https://api.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/deltas/${DELTA_ID}" \
  -X PATCH \
  -H "Authorization: Bearer ${HUMANITEC_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '[
  {
    "shared: [
      {
        "op": "add",
        "path": "/spec/shared/'${RES_ID}'".
        "value": { "type": "'${RES_TYPE}'" }
      }
    ]
  }
]'

Where the following environment variables are set:

Variable Example Description
DELTA_ID 612304986f51413 The ID of an existing, unarchieved delta.
RES_ID users-db The ID of the shared resource.
RES_TYPE postgres The resource type of the resource.
HUMANITEC_TOKEN lsakdjhcals A Humanitec token of a user with at least Developer permission on the Application.
HUMANITEC_ORG my-org The Humanitec organization the Application is in.
HUMANITEC_APP my-app The Application to add the shared resource to.

This action cannot be performed via Terraform, as it involves updating an ephemeral object.

Results: The shared resource are added to the list of shared resources for the Application.

Private Resource dependencies

Private Resource Dependencies in Humanitec describe dependencies on resources that are only available to a single Workload in an Application. The main purpose of this is to make it easier to reason about which workload “owns” a particular resource, such as a database.

To create a Private Resource, you can use the Humanitec UI, CLI, or API. This allows you to specify the details of the resource, such as the type of resource (for example, database, domain name), the configuration and settings, and the access controls. Once the Shared Resource has been created, it will be available to all Workloads in the Application, so they can access and use it as needed.

Add shared Resource to an Application

  1. From the Application overview, select the name of the Application in which you would like to add a private dependent resource to.

  2. Click on the workload you want to add the dependency to.

  3. On the left-hand side, under Resource dependencies, select the Add resource drop down and select a resource type to add from the list.

  4. Enter a unique resource ID and select Done to create the shared resource.

Results: The private resource dependency is added to the list of private resources for the Workload.

You can view, edit, or delete the resource by selecting the corresponding options from the dropdown menu next to the resource.

humctl update delta ${DELTA_ID} add /modules/${WORKLOAD_ID}/externals/${RES_ID} '{ "type": "'${RES_TYPE}'" }'

Where the following environment variables are set:

Variable Example Description
DELTA_ID 612304986f51413 The ID of an existing, unarchieved delta.
WORKLOAD_ID my-workload The ID of the workload to add the resource dependency to.
RES_ID users-db The ID of the shared resource.
RES_TYPE postgres The resource type of the resource.

curl "https://api.humanitec.io/orgs/${HUMANITEC_ORG}/apps/${HUMANITEC_APP}/deltas/${DELTA_ID}" \
  -X PATCH \
  -H "Authorization: Bearer ${HUMANITEC_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '[
  {
    "modules: {
      "update": {
        "'${WORKLOAD_ID}'": [
          {
            "op": "add",
            "path": "/externals/'${RES_ID}'".
            "value": { "type": "'${RES_TYPE}'" }
          }
        ]
      }
    }
  }
]'

Where the following environment variables are set:

Variable Example Description
DELTA_ID 612304986f51413 The ID of an existing, unarchieved delta.
WORKLOAD_ID my-workload The ID of the workload to add the resource dependency to.
RES_ID users-db The ID of the shared resource.
RES_TYPE postgres The resource type of the resource.
HUMANITEC_TOKEN lsakdjhcals A Humanitec token of a user with at least Developer permission on the Application.
HUMANITEC_ORG my-org The Humanitec organization the application is in.
HUMANITEC_APP my-app The Application to add the shared resource to.

This action cannot be performed via Terraform, as it involves updating an ephemeral object.

Top