Details
-
New Feature
-
Status: Closed
-
Normal
-
Resolution: Fixed
-
None
-
None
Description
In order to convert values from hiera backends to rich data values not directly representable in plain YAML/JSON, the lookup_options should be given a new key convert_to that accepts either a type name (for example "Sensitive"), or an array of type name and arguments to the type's new function.
This is of value as there is no way to represent certain data types directly in JSON, YAML, etc. and there is no way to have any logic post process a looked up value before it is assigned to a class parameter when using APL.
If a simple data type is used (for example Sensitive) it is expected that this type has a single argument constructor that accepts the looked up value and returns an instance of the specified data type. If the constructor is more complex and needs additional arguments, or where its single argument constructor is not appropriate for the use case, an array of typename + arguments is instead used. An example could be interpretation of a String in a particular format used to construct a time/date value.
The type entry in lookup_options is a String with a valid Puppet Type System specification of a data type, thereby also adding type matching - since a `new` will check that what is produced is compliant with any type constraints expressed in the type.
Example - Making a value Sensitive
mymodule::mykey: 42
|
lookup_options:
|
mymodule::mykey:
|
convert_to: "Sensitive"
|
Example - turning a non Array value into an array:
mymodule::mykey: 42
|
lookup_options:
|
mymodule::mykey:
|
convert_to:
|
- "Array"
|
- true
|