For increased flexibility, you can add expressions to Cloud Assembly blueprint code.
An expression is formed by using the ${expression} construct.
Literals
There are literals for boolean, integer, floating point, string, and null in an expression:
Boolean (true or false) Integer Floating point String (Backslash escapes single quote, double quote, and backslash itself, so " is escaped as \", ' is escaped as \', and \ is escaped as \\. Quotes only need to be escaped inside a string enclosed with the same type of quote.) Null
Environment variables
Syntax:
env.ENV_NAME
Environment names:
orgId projectId projectName deploymentId deploymentName blueprintId blueprintVersion blueprintName requestedBy (user) requestedAt (time)
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 string for non-clustered (count not specified), return array for clustered resource ${resource.app[0].id} - return first entry for clustered resource
Resource self variables
Resource self variables are allowed only for resources supporting the allocation phase (for most Cloud.*
properties).
Syntax:
self.PROPERTY_NAME
Example:
${self.address} - return address assigned during allocation phase
Cluster count index
Syntax:
count.index
Example:
${count.index == 0 ? "master" : "slave"} - return resource index for clustered resources
Conditions
Syntax:
Equality operators: == != Relational operators: < > <= >= Logical operators: && || ! Conditional operator: condition-expression ? true-expression : false-expression
Examples:
${input.count < 5 && input.size == 'small'} ${input.count < 2 ? "small" : "large"}
Arithmetic operators
Syntax:
Operators: + - / * %
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:
expr.identifier is equivalent to expr["identifier"]; that is, 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}
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)}
List of functions:
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 format and values, using stringf format 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 JsonPath 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