Documentation for version v0.39.0 is no longer actively maintained. The version you are currently viewing is a static snapshot. For up-to-date documentation, see the latest version.
Using Data Values
Overview ¶
The way to introduce a variable in ytt
(i.e. to externalize a configuration value) is to:
- declare it as a “Data Value” by naming it in a schema file,
- reference it in templates, and
- configure it through Data Value inputs.
This guide shows how to do this.
(For a high-level overview of ytt
, see How it works.)
Declaring Data Values ¶
In ytt
, before a Data Value can be used in a template, it must be declared. This is typically done in a schema file.
For example:
schema.yml
#@data/values-schema
---
load_balancer:
enabled: true
external_ip: ""
declares three Data Values:
load_balancer
is a map that contains two map items:enabled
andexternal_ip
.load_balancer.enabled
is a boolean; by default it istrue
.load_balancer.external_ip
is a string; by default it is an empty string.
(see the How To Write Schema guide, for details.)
Referencing Data Values ¶
Those Data Values can then be used in a template via the @ytt:data
module.
config.yml
#@ load("@ytt:data", "data")
---
service: #@ data.values.load_balancer
(For details on using the Data module, refer to @ytt:data
.)
Configuring Data Values ¶
Further, those Data Values can be customized by a Consumer by providing their own data values:
values.yml
#@data/values
---
load_balancer:
external_ip: 172.120.12.232
When Data Values are supplied, their values are checked against the schema to ensure they are of the right type and shape. If there are any errors, ytt
stops processing and reports them.
(For details on how to configure Data Values, consult the Data Values reference.)
…
Using the example files from above, ytt
produces this output:
$ ytt -f schema.yml -f values.yml -f config.yml
service:
load_balancer:
enabled: true
external_ip: 172.120.12.232
Note:
load_balancer.enabled
is the default as set inschema.yml
load_balancer.external_ip
is the configured value fromvalues.yml
Next Steps ¶
More examples:
- simple and complete example of declaring and using Data Values through schema:
https://github.com/carvel-dev/ytt/tree/develop/examples/schema - example declaring and configuring an array:
https://github.com/carvel-dev/ytt/tree/develop/examples/schema-arrays
Related documentation:
(Help improve our docs: edit this page on GitHub)