The vRealize Automation Cloud Assembly blueprint expression syntax exposes all of the capabilities of expressions.
The syntax is only partly represented in the examples shown in How to use expressions to make vRealize Automation Cloud Assembly blueprint code more versatile.
Literals
The following literals are supported:
- Boolean (true or false)
- Integer
- Floating point
- String
Backslash escapes double quote, single quote, and backslash itself:
"
is escaped as\"
'
is escaped as\'
\
is escaped as\\
Quotes only need to be escaped inside a string enclosed with the same type of quote, as shown in the following example.
"I am a \"double quoted\" string inside \"double quotes\"."
- Null
Environment variables
Environment names:
- orgId
- projectId
- projectName
- deploymentId
- deploymentName
- blueprintId
- blueprintVersion
- blueprintName
- requestedBy (user)
- requestedAt (time)
Syntax:
env.ENV_NAME
Example:
${env.blueprintId}
Resource variables
Resource variables let you bind to resource properties from other resources.
Syntax:
resource.RESOURCE_NAME.PROPERTY_NAME
Examples:
${resource.db.id}
${resource.db.networks[0].address}
${resource.app.id}
(Return the string for non-clustered resources, where count isn't specified. Return the array for clustered resources.)${resource.app[0].id}
(Return the first entry for clustered resources.)
Resource self variables
Resource self variables are allowed only for resources supporting the allocation phase. Resource self variables are only available (or only have a value set) after the allocation phase is complete.
Syntax:
self.property_name
Example:
${self.address}
(Return the address assigned during the allocation phase.)
Note that for a resource named resource_x
, self.property_name
and resource.resource_x.property_name
are the same and are both considered self-references.
Cluster count index
Syntax:
count.index
Example:
${count.index == 0 ? "primary" : "secondary"}
(Return the node type for clustered resources.)
Limitations:
Use of count.index
for resource allocation is not supported. For example, the following capacity expression fails when it references the position within an array of disks created at input time.
inputs: disks: type: array minItems: 0 maxItems: 12 items: type: object properties: size: type: integer title: Size (GB) minSize: 1 maxSize: 2048 resources: Cloud_vSphere_Disk_1: type: Cloud.vSphere.Disk properties: capacityGb: '${input.disks[count.index].size}' count: '${length(input.disks)}'
Conditions
Syntax:
- Equality operators are
==
and!=
. - Relational operators are
<
>
<=
and>=
. - Logical operators are
&&
||
and!
. - Conditionals use the pattern:
condition-expression
?
true-expression:
false-expression
Examples:
${input.count < 5 && input.size == 'small'}
${input.count < 2 ? "small" : "large"}
Arithmetic operators
Syntax:
Operators are +
–
/
*
and %
.
Example:
${(input.count + 5) * 2}
String concatenation
Syntax:
${'ABC' + 'DEF'}
evaluates to ABCDEF
.
Operators [ ] and .
The expression follows ECMAScript in unifying the treatment of the [ ] and . operators.
So, expr.identifier
is equivalent to expr["identifier"]
. The identifier is used to construct a literal whose value is the identifier, and then the [ ] operator is used with that value.
Example:
${resource.app.networks[0].address}
In addition, when a property includes a space, delimit with square brackets and double quotes instead of using dot notation.
Incorrect:
input.operating system
Correct:
input["operating system"]
Construction of map
Syntax:
${{'key1':'value1', 'key2':input.key2}}
Construction of array
Syntax:
${['key1','key2']}
Example:
${[1,2,3]}
Functions
Syntax:
${function(arguments...)}
Example:
${to_lower(resource.app.name)}
Function | Description |
---|---|
abs(number) | Absolute number value |
floor(number) | Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer |
ceil(number) | Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer |
to_lower(str) | Convert string to lower case |
to_upper(str) | Convert string to upper case |
contains(array, value) | Check if array contains a value |
contains(string, value) | Check if string contains a value |
join(array, delim) | Join array of strings with a delimiter and return a string |
split(string, delim) | Split string with a delimiter and return array of strings |
slice(array, begin, end) | Return slice of array from begin index to end index |
reverse(array) | Reverse entries of array |
starts_with(subject, prefix) | Check if subject string starts with prefix string |
ends_with(subject, suffix) | Check if subject string ends with suffix string |
replace(string, target, replacement) | Replace string containing target string with target string |
substring(string, begin, end) | Return substring of string from begin index until end index |
format(format, values...) | Return a formatted string using Java Class Formatter format and values. |
keys(map) | Return keys of map |
values(map) | Return values of map |
merge(map, map) | Return a merged map |
length(string) | Return string length |
length(array) | Return array length |
max(array) | Return maximum value from array of numbers |
min(array) | Return minimum value from array of numbers |
sum(array) | Return sum of all values from array of numbers |
avg(array) | Return average of all values from array of numbers |
digest(value, type) | Return digest of value using supported type (md5, sha1, sha256, sha384, sha512) |
to_string(value) | Return string representation of the value |
to_number(string) | Parse string as number |
not_null(array) | Return the first entry which is not null |
base64_encode(string) | Return base64 encoded value |
base64_decode(string) | Return decoded base64 value |
now() | Return current time in ISO-8601 format |
uuid() | Return randomly generated UUID |
from_json(string) | Parse json string |
to_json(value) | Serialize value as json string |
json_path(value, path) | Evaluate path against value using XPath for JSON. |
matches(string, regex) | Check if string matches a regex expression |
url_encode(string) | Encode string using url encoding specification |
trim(string) | Remove leading and trailing spaces |