Skip to main content
XCL provides built-in functions for common operations on strings, collections, and other values. Functions are called with the standard name(arg1, arg2) syntax and can appear anywhere an expression is valid.
locals "s" {
    upper_name = upper(input.name)
    joined     = join(",", input.azs)
    tag_count  = len(input.tags)
}
The typechecker records function call expressions but does not validate function names or argument counts — that validation happens at the Pulumi Python runtime. Unrecognized function names produce runtime errors, not compile-time errors.

String functions

FunctionDescription
upper(s)Convert string to uppercase
lower(s)Convert string to lowercase
trimspace(s)Strip leading and trailing whitespace
trim(s, chars)Strip specified characters from both ends
trimprefix(s, prefix)Remove prefix if present
trimsuffix(s, suffix)Remove suffix if present
replace(s, old, new)Replace all occurrences of old with new
split(sep, s)Split string into a list on separator
join(sep, list)Join list of strings with separator
contains(s, substr)True if string contains substring
startswith(s, prefix)True if string starts with prefix
endswith(s, suffix)True if string ends with suffix
format(fmt, args...)Printf-style string formatting
substr(s, offset, length)Extract substring

Collection functions

FunctionDescription
len(coll)Number of elements in a list, map, or string
keys(m)List of map keys
values(m)List of map values
flatten(lists)Flatten a list of lists into one list
distinct(list)Remove duplicate values
sort(list)Sort list of strings or numbers
reverse(list)Reverse a list
concat(a, b)Concatenate two lists
slice(list, start, end)Extract a sublist
lookup(map, key, default)Look up map key with fallback
merge(a, b)Merge two maps (b wins on collision)
zipmap(keys, values)Create a map from parallel key/value lists
toset(list)Convert list to set (deduplicate)
tolist(set)Convert set to sorted list

Encoding functions

FunctionDescription
jsonencode(value)Encode value as JSON string
jsondecode(s)Decode JSON string to value
base64encode(s)Base64-encode a string
base64decode(s)Decode a base64 string
urlencode(s)URL-encode a string

Numeric functions

FunctionDescription
min(a, b)Minimum of two numbers
max(a, b)Maximum of two numbers
abs(n)Absolute value
ceil(n)Round up
floor(n)Round down
pow(base, exp)Exponentiation

Type conversion functions

FunctionDescription
tostring(v)Convert value to string
tonumber(s)Parse string as number
tobool(s)Parse string as boolean

Conditional / null helpers

FunctionDescription
coalesce(vals...)Return first non-null value
can(expr)Return true if expression evaluates without error

Usage in expressions

Functions compose naturally with other expressions:
locals "s" {
    // join a list of AZ names
    az_string = join(", ", input.azs)

    // uppercase environment prefix for resource names
    env_upper = upper(input.env)

    // derive bucket name from inputs
    bucket_name = lower(f"{input.project}-{input.env}-artifacts")

    // safe map lookup with default
    tier = lookup(input.tiers, input.env, "standard")
}