Variables
To use variables and constants at deploy time you need to have two things:
- a manifest that you want to template a value in
- a defined variable in the
zarf.yaml
file fromvariables
orsetVariable
The manifest should have your desired variable name in ALL CAPS prefixed with ###ZARF_VAR
for variables
or prefixed with ###ZARF_CONST
for constants
and suffixed with ###
. For example in a configmap that took a variable named DATABASE_USERNAME
you would provide the following:
apiVersion: v1kind: ConfigMapmetadata: name: db-configmapdata: username: ###ZARF_VAR_DATABASE_USERNAME###
In the zarf.yaml
, you would need to define the variable in the variables
section or as output from an action with setVariable
with the same name
as above. Or for a constant you would use the constants
section. For the same example as above, you would have the following for a variable defined by the deploy user:
variables: name: DATABASE_USERNAME description: 'The username for the database'
And the following for a variable defined as an output from an action:
components: - name: set-variable-example actions: onDeploy: after: - cmd: echo "username-value" setVariables: - name: DATABASE_USERNAME
Zarf variables
can also have additional fields that describe how Zarf will handle them which are described below:
Field | Type | Description |
---|---|---|
name * | string | The name to be used for the variable |
autoIndent | boolean | Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_VAR_. |
default | string | The default value to use for the variable |
description | string | A description of the variable to be used when prompting the user a value |
pattern | string | An optional regex pattern that a variable value must match before a package can be deployed. |
prompt | boolean | Whether to prompt the user for input for this variable |
sensitive | boolean | Whether to mark this variable as sensitive to not print it in the Zarf log |
type | string | Changes the handling of a variable to load contents differently (i.e. from a file rather than as a raw variable - templated files should be kept below 1 MiB) |
Zarf constants
are similar but have fewer options as they are static by the time zarf package deploy
is run:
Field | Type | Description |
---|---|---|
value * | string | The value to set for the constant during deploy |
name * | string | The name to be used for the constant |
autoIndent | boolean | Whether to automatically indent the variable's value (if multiline) when templating. Based on the number of chars before the start of ###ZARF_CONST_. |
description | string | A description of the constant to explain its purpose on package create or deploy confirmation prompts |
pattern | string | An optional regex pattern that a constant value must match before a package can be created. |
For user-specified variables, you can also specify a default
value for the variable to take in case a user does not provide one on deploy, and can specify whether to prompt
the user for the variable when not using the --confirm
or --set
flags.
variables: name: DATABASE_USERNAME default: 'postgres' prompt: true
For constants, you must specify the value they will use at package create. These values cannot be overridden with --set
during zarf package deploy
, but you can use package template variables (described below) to variablize them during zarf package create
.
constants: name: DATABASE_TABLE value: 'users'
You can also specify package configuration templates at package create time by including ###_ZARF_PKG_TMPL_*###
as the value for any string-type data in your package definition. These values are discovered during zarf package create
and will always be prompted for if not using --confirm
or --set
. An example of this is below:
kind: ZarfPackageConfigmetadata: name: 'pkg-variables' description: 'Prompt for a variables during package create'
constants: - name: PROMPT_IMAGE value: '###ZARF_PKG_TMPL_PROMPT_ON_CREATE###'
components: - name: zarf-prompt-image required: true images: - '###ZARF_PKG_TMPL_PROMPT_ON_CREATE###'