Placeholders
Placeholders in Deployment Sets
Humanitec uses Placeholders to insert values that will only be known at deployment time into Application Configuration. Placeholders use a syntax that is similar to Template literals in JavaScript or variable substitution in shell scripting languages such as Bash and PowerShell.
The syntax is as follows:
${path}
Where
path
is made up of .
separated tokens or JSON strings enclosed in []
. The following all evaluate to the same placeholder:${shared.users-db.name}
${["shared"]["users-db"]["name"]}
${shared['users-db'].name}
A literal
${
can be inserted by escaping the {
with a backslash.$\{path}
This will evaluate to
${path}
.Multiple placeholders can be used in a string, for example when specifying a connection string to a database:
postgresql://${shared.users-db.username}:${shared.users-db.password}@${shared.users-db.host}:${shared.users-db.port}/${shared.users-db.name}
The
lables
, variables
and files
properties of workloads in Deployment Sets support Placeholders. Placeholders are a way of injecting values into strings that are only known at deployment time. They are the mechanism that allows Deployment Sets to be environment agnostic.If a placeholder refers to a secret value (e.g. a database password) then the string it is a part of will also be treated as a secret by Humanitec.
There are some placeholders that cannot be used as secrets. In these cases, if they are included in a string that contains other placeholder that are secret, an error will be thrown. These placeholders are documented.
Placeholders can only be used in certain fields in Humanitec. These fields are:
Path | Location | Description |
---|---|---|
shared.{id}.{resourceOutput} | variables , files | |
externals.{id}.{resourceOutput} | labels , variables , files | |
modules.{workloadId}.service.name | labels , variables , files | The in-cluster name of the service exposing a workload. |
values.{sharedValueId} | labels , variables , files | A Shared Application Value or Secret. |
context.app.id | labels , variables , files , driver_inputs | |
context.env.id | labels , variables , files , driver_inputs | |
context.res.id | driver_inputs | |
pod.{value...} | variables | Metadata and Status information about the current Pod retrieved via the Kubernetes Downward API. This placeholder cannot be combined with other values that are secrets. |
containers.{containerId}.{value...} | variables | Metadata about a particular container in a Pod retrieved via the Kubernetes Downward API. This placeholder cannot be combined with other values that are secrets. |
resources.{type#id}.outputs.{value...} | driver_inputs | A Resource Reference placeholder. Resolves to the output of another resource defined by type#id . (#id is optional) |
In the UI, inputs for
labels
, variables
, and files
support placeholder autocompletion. Type ${
in the input area to see a complete list of available placeholders.A database connection string to a PostgreSQL Database added as a Private Resource Dependency with ID
users-db
to a workload.postgresql://${externals.users-db.username}:${externals.users-db.password}@${externals.users-db.host}:${externals.users-db.port}/${externals.users-db.name}
Referencing the DNS name of a shared DNS resource with ID
api
${shared.api.host}
Referencing the Stripe API Key stored as a secret in Shared App Values under the ID
STRIPE_API_KEY
:${values.STRIPE_API_KEY}
Constructing an in-cluster URL to make requests to another workload with ID
other-workload
:http://${modules.other-workload.service.name}:8080/products
Defining a template for a DNS subdomain for an environment:
${context.env.id}-api-${context.app.id}
Referencing the name of the current Pod:
${pod.metadata.name}
NOTE: This value will be different on every replica.
Referencing the current namespace:
${pod.metadata.namespace}
Referencing the IP of the node the Pod is running on:
${pod.hostIP}
NOTE: This may vary between replicas of the same Pod.
Referencing the CPU limit for a container with ID
main
in the current Pod:${containers.main.limits.cpu}
Last modified 4mo ago