Carvel Logo

Using Data Values

Overview

The way to introduce a variable in ytt (i.e. to externalize a configuration value) is to:

  1. declare it as a “Data Value” by naming it in a schema file,
  2. reference it in templates, and
  3. 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 and external_ip.
  • load_balancer.enabled is a boolean; by default it is true.
  • 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 in schema.yml
  • load_balancer.external_ip is the configured value from values.yml

Next Steps

More examples:

Related documentation: