Workload Variables
Use Score to pass environment configurations at the Workload level.
On this page
Values and Secrets are defined inside the Humanitec application and can be set Environment wide.
However, you can define Workload level Values and Secrets with Score.
Overview
The Score Specification uses a special environment
property type that is specified in the resources
section.
apiVersion: score.sh/v1b1
metadata:
name: hello-world
containers:
hello:
image: busybox
command: ["/bin/sh"]
args: ["-c", "while true; do echo Hello $${FRIEND}!; sleep 5; done"]
variables:
FRIEND: ${resources.env.NAME}
resources:
env:
type: environment
properties:
NAME:
type: string
default: World
Resources need to map to the resource structure.
To declare environment variables in a Score file, the variable name,
resources.env.NAME
must map to the structure in resource
section.Use the run
command to generate a Humanitec deployment delta file from Score.
score-humanitec run -f ./score.yaml \
--env test-env
The following is the output of the previous command.
{
"metadata": {
"env_id": "test-env",
"name": "Auto-generated (SCORE)"
},
"modules": {
"add": {
"hello-world": {
"profile": "humanitec/default-module",
"spec": {
"containers": {
"hello": {
"args": [
"-c",
"while true; do echo Hello $${FRIEND}!; sleep 5; done"
],
"command": ["/bin/sh"],
"id": "hello",
"image": "busybox",
"variables": {
"FRIEND": "${values.NAME}"
}
}
}
}
}
}
}
}
The output JSON can be used as a payload to Create a new Delta with a Humanitec API call.
When deploying this service with Humanitec, make sure the shared application value called NAME
is created and set for the target environment.