Skip to main content
ubx provides 30 built-in functions usable in any attribute expression. When any argument is Pending<T>, the result is automatically wrapped in .apply().

Interactive Testing

ubx console
> lower("HELLO")
"hello"
> cidrsubnet("10.0.0.0/16", 8, 2)
"10.0.2.0/24"

String Functions

FunctionDescriptionExample
lower(s)Lowercaselower("PROD")"prod"
upper(s)Uppercaseupper("dev")"DEV"
replace(s, old, new)Replace allreplace("a-b", "-", "_")"a_b"
trim(s)Strip whitespacetrim(" x ")"x"
trimprefix(s, prefix)Remove prefixtrimprefix("pre-x", "pre-")"x"
trimsuffix(s, suffix)Remove suffixtrimsuffix("x-suf", "-suf")"x"
split(sep, s)Split to listsplit(",", "a,b")["a","b"]
join(sep, list)Join listjoin("-", ["a","b"])"a-b"
format(fmt, ...args)sprintfformat("%s-%s", "a", "b")"a-b"
strlen(s)Lengthstrlen("hello")5

Collection Functions

FunctionDescriptionExample
length(list)Count itemslength(["a","b"])2
keys(obj)Object keyskeys({a="1"})["a"]
values(obj)Object valuesvalues({a="1"})["1"]
merge(obj1, obj2)Merge objectsmerge({a="1"},{b="2"}){a="1",b="2"}
contains(list, val)Membershipcontains(["a","b"],"a")true
lookup(obj, key, def)Key + fallbacklookup({a="1"},"b","x")"x"
flatten(list)Flatten nestedflatten([["a"],["b"]])["a","b"]
distinct(list)Remove dupesdistinct(["a","a","b"])["a","b"]

Type Conversion

FunctionDescriptionExample
tostring(v)To stringtostring(42)"42"
tonumber(v)To numbertonumber("42")42
tobool(v)To booleantobool(1)true

Numeric Functions

FunctionDescriptionExample
min(a, b)Smallermin(3, 5)3
max(a, b)Largermax(3, 5)5
abs(n)Absolute valueabs(-7)7
ceil(n)Round upceil(1.3)2
floor(n)Round downfloor(1.9)1

Encoding Functions

FunctionDescriptionExample
jsonencode(v)To JSONjsonencode({a="1"})'{"a":"1"}'
jsondecode(s)Parse JSONjsondecode("{}"){}
base64encode(s)Base64 encodebase64encode("hi")"aGk="
base64decode(s)Base64 decodebase64decode("aGk=")"hi"

IP/CIDR Functions

FunctionDescriptionExample
cidrsubnet(cidr, bits, idx)Subnet CIDRcidrsubnet("10.0.0.0/16", 8, 1)"10.0.1.0/24"
cidrhost(cidr, idx)Host IPcidrhost("10.0.0.0/24", 5)"10.0.0.5"
cidrnetmask(cidr)Netmaskcidrnetmask("10.0.0.0/24")"255.255.255.0"
cidrprefix(cidr)Prefix lengthcidrprefix("10.0.0.0/24")24

Pending<T> Propagation

# Resolved — emitted inline
bucket = lower("PROD")
# → ("PROD").toLowerCase()

# Pending — single arg wraps in .apply()
bucket = lower(~unit.aws_s3_bucket_v2.src.bucket)
# → src.bucket.apply(_dep0 => (_dep0).toLowerCase())

# Multiple pending args — uses pulumi.all()
bucket = join("-", [~unit.x.y.name, ~unit.z.w.id])
# → pulumi.all([x.name, z.id]).apply(([_dep0, _dep1]) => [_dep0, _dep1].join("-"))