Template functions
StackState Self-hosted v4.5.x
This page describes StackState v4.5.x. The StackState 4.5 version range is End of Life (EOL) and no longer supported. We encourage customers still running the 4.5 version range to upgrade to a more recent release.
Overview
StackState Template JSON (STJ) incorporates several custom handlebars functions that can be used, for example, to get existing nodes from the graph, create new nodes or join texts together. The available StackState functions are described below.
Functions
add
add
Adds number variables together.
Arguments
Two or more number variables.
Examples
concat
concat
The concat
function concatenates two values:
get
get
The get
function finds a node of a certain type by its unique identifier without needing to specify the type of the node. The function finds a node in a nested way, first finding the identifier and then finding the type and name in the scope of the first resolved node.
Examples
Resolve the
Production
Environment
using:Resolve the
Parameters
metrics
from the CheckFunction identified byurn:stackpack:aws:check_function:basic
using:
getFirstExisting
getFirstExisting
Gets the first node from a list of node identifiers (URNs).
Arguments
Two or more URNs strings.
Examples
getOrCreate
getOrCreate
The getOrCreate
function first tries to resolve a node by its identifier and then by the fallback create-identifier. If none are found, the function will create a node using the specified Type
and Name
arguments and the newly created node will be identified with the create-identifier value.
Note that:
getOrCreate
works only with the following (simple) types: Environment, Layer, Domain, ComponentType and RelationType.create-identifier
must be a value in the"urn:system:auto"
namespace.
We strongly encourage to use get
and getOrCreate
as resolving nodes by identifier is safer than by name due to the unique constraint enforced in the identifier
values.
Examples
Find the Production
Environment
by its identifier and fallback identifier, or otherwise create it:
identifier
identifier
The identifier
function creates an identifier out of an identifier prefix, a component type and a component name.
include
include
This function will only work when the template is loaded from a StackPack.
Includes the content of another file inside this template. This can come in handy when template files become exceedingly large, when working with images or when you want to reuse the same template fragments in multiple locations.
Arguments
filename - The name of the file to include from the StackPack. The file must exist in the
provisioning
directory or one of its sub-directories (see StackPack packaging.encoding (optional, default =
handlebars
) - Choice of:handlebars
- Included file will be interpreted as StackState Templated JSON.identity
- Included file will be not be interpreted, but simply will be included as text.base64
- Included file will be loaded using a BASE64 encoding. This is possible for the image types:png
,jpg
,gif
andsvg
.
Examples
Include a script:
Include an image:
join
join
Joins array or map data as a text usign a separator, prefix and suffix. This is especially handy when producing JSON arrays.
Arguments
iteratee - the element to repeat and join together.
separator - the text that is used to separate the elements.
prefix (optional) - text that is placed at the beginning of the joined text.
suffix (optional) - text is appended at the end of the joined text.
Examples
Join an array of labels to create a JSON array of objects:
Join a map of labels to create a JSON array of objects:
See also
Last updated