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 Environment) 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
can be used:
${externals.my-db.name}
Shared Resource dependencies
Shared Resources Dependencies in the Humanitec Platform Orchestrator are dependencies on resources that are available to all Workloads in an Application Environment. 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 Environment, so they can access and use it as needed.
Adding a Shared Resource
-
From the Application overview , select the name of the Application you’d like to add shared resources to.
-
Select the Environment.
-
Select Create draft delta
-
Select Shared resources and select the Add resource dependency button and select a resource to add from the list.
-
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. Use the form {resourceType}.{resourceClass} if class is not default . |
humctl help update delta
.
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. Use the form {resourceType}.{resourceClass} if class is not default . |
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.
Shared Resources in Score
Score
has the concept of a resource id
which, from the viewpoint of an application developer, simply means “some external Resource identifier”. When two resources share the same type
, class
, and id
, they are considered the same resource when used across related workloads, i.e. all Workloads in the same Application Environment.
A resource having an id
in Score will be provisioned as a Shared Resource in the Platform Orchestrator. It will receive a resource id of shared.<id>
in the
Resource Graph
.
All workloads in the same Environment requesting the same resource, i.e. same type
, class
, and id
, will effectively share that same resource, as seen in these Score snippets:
# Workload 1
resources:
my-internal-name-for-this-resource:
type: s3
id: s3-common
# No class specified, so the effective class is "default"
# Workload 2
resources:
my-different-name-for-this-resource:
type: s3
id: s3-common
# No class specified, so the effective class is "default"
Note that the resource names my-internal-name-for-this-resource
and my-different-name-for-this-resource
are local to the respective Score file. References to ${resources.my-internal-name-for-this-resource...}
in the first and ${resources.my-different-name-for-this-resource...}
in the second Score file will resolve to the same resource.
This Score example shows another real-life application of Shared Resources.
Shared Resources are also used in the Delegator Resource Graph pattern .
Private Resource dependencies
Private Resource Dependencies in the Humanitec Platform Orchestrator 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 private Resource to an Application
-
From the Application overview , select the name of the Application in which you would like to add a private dependent resource to.
-
Select the Environment.
-
Select Create draft delta
-
Click on the workload you want to add the dependency to.
-
Under Resource dependencies, select the Add resource dependency button and select a resource type to add from the list.
-
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. Use the form {resourceType}.{resourceClass} if class is not default . |
humctl help update delta
.
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 Rype of the Resource. Use the form {resourceType}.{resourceClass} if class is not default . |
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.