Data type syntax

Each value in the Puppet language has a data type, like “string.” There is also a set of values whose data type is “data type.” These values represent the other data types. For example, the value String represents the data type of strings. The value that represents the data type of these values is Type.

You can use these special values to examine a piece of data or enforce rules. For example, you can test whether something is a string with the expression $possible_string =~ String, or specify that a class parameter requires string values with class myclass (String $string_parameter = "default value") { ... }.

Syntax

Data types are written as unquoted upper-case words, like String.

Data types sometimes take parameters, which make them more specific. For example, String[8] is the data type of strings with a minimum of eight characters.

Each known data type defines how many parameters it accepts, what values those parameters take, and the order in which they must be given. Some of the abstract types require parameters, and most types have some optional parameters available.

The general form of a data type is:

  • An upper-case word matching one of the known data types.

  • Sometimes, a set of parameters, which consists of:

    • An opening square bracket [ after the type’s name. There can’t be any space between the name and the bracket.

    • A comma-separated list of values or expressions. Arbitrary whitespace is allowed, but you can’t have a trailing comma after the final value.

    • A closing square bracket ].

The following example uses an abstract data type Variant, which takes any number of data types as parameters. One of the parameters provided in the example is another abstract data type Enum, which takes any number of strings as parameters:

Variant[Boolean, Enum['true', 'false', 'running', 'stopped']]

When parameters are required, you must specify them. The only situation when you can leave out required parameters is if you’re referring to the type itself. For example, Type[Variant] is legal, even though Variant has required parameters.