Carvel Logo

Using Data Values


A Configuration Author introduces variables in ytt (i.e. to externalize configuration values) by:

  1. declaring them as “Data Values” by naming it in a schema file and then,
  2. referencing them in templates.

Configuration Consumers then set values for those variables in any combination of:

  • one or more of the --data-value... flag(s) and/or
  • Data Values Overlay(s) through the --file flag

This guide illustrates how to declare and configure data values.

(for a higher-level overview of ytt, see How it works.)

Declaring Data Values

In ytt, before a Data Value is used, it is declared. This is typically done in a schema file.

For example:


name: monitor
  virtual_host_fqdn: "monitor.system.example"
  service_port: 80
  enable_tls: false

declares five Data Values:

  • name contains a string; the default name is “monitor”.
  • ingress is a map that contains three map items: virtual_host_fqdn, service_port, and enable_tls.
  • ingress.virtual_host_fqdn is a string; by default, the fully-qualified host name is the value given.
  • ingress.service_port is an integer; by default, the service is listening on the standard HTTP port.
  • ingress.enable_tls is a boolean; by default, transport layer security is off.

(see the How To Write Schema guide, for details.)

Referencing Data Values

Those Data Values can then be referred to in template(s):


#@ load("@ytt:data", "data")
name: #@
  virtualhost: #@ data.values.ingress.virtual_host_fqdn
  - port: #@ data.values.ingress.service_port
  #@ if/end data.values.ingress.enable_tls:
  - port: 443


  • load("@ytt:data", "data") imports the the data struct from the @ytt:data module
  • data.values contains all of the declared data values
  • #@ if/end only includes the annotated array item if the data value ingress.enable_tls is true.

Using the defaults given in the schema, ytt produces:

$ ytt -f schema.yml -f config.yml
name: monitor
  virtualhost: monitor.system.example
  - port: 80

(For details on using the Data module, refer to @ytt:data.)

Configuring Data Values

Those Data Values can be configured by a Consumer:

This is done, typically, via a Data Values File:


name: observer
  virtual_host_fqdn: "observer.system.example"
  enable_tls: true

which is a plain YAML file (i.e. cannot contain any ytt templating). This file is specified through the --data-values-file flag.

Using the example files from above, ytt produces this output:

$ ytt -f schema.yml -f config.yml --data-values-file values.yml
name: observer
  virtualhost: observer.system.example
  - port: 80
  - port: 443

Supplied Data Values are automatically checked against the schema. If any value is of the wrong type, ytt reports the discrepancies and stops processing.

(For details on how to configure Data Values, consult the Data Values reference.)




Blog Articles:

(Help improve our docs: edit this page on GitHub)