Skip to main content
ubx ships with 55 built-in functions covering every category you need for infrastructure configuration: string manipulation, collection operations, encoding and hashing, type conversion, math, CIDR networking calculations, date formatting, and a handful of utilities like uuid() and range(). All functions are evaluated at compile time from Resolved<T> inputs and locals — they don’t require cloud credentials, don’t make network calls, and produce values that are inlined directly into the generated Pulumi program. This tutorial is a complete reference with one working example per function, grouped by category, so you can find the function you need and see exactly what it produces.

What you’ll learn

  • All 55 built-in functions organised by category
  • The input and output type of each function
  • How functions compose in local blocks and resource attributes

Why this matters

Built-in functions eliminate the need for external scripting or complex workarounds for common operations. Instead of a separate Python script to compute a CIDR subnet, cidrsubnet("10.0.0.0/16", 4, 2) does it inline. Instead of manually formatting a timestamp, formatdate("2006-01-02", timestamp()) produces the right string. Everything stays in .iac source.

The source code

# Sample resource using a selection of functions
unit "aws_s3_bucket_v2" "demo" {
  bucket = lower(join("-", ["MYAPP", "demo", "bucket"]))
  tags   = merge({ ManagedBy = "ubx" }, { CreatedAt = timestamp() })
}

Function categories at a glance

CategoryFunctionsCount
Stringlower, upper, replace, trim, trimprefix, trimsuffix, trimspace, split, join, format, strlen, startswith, endswith, indent, chomp, regex, regexall17
Collectionlength, keys, values, merge, contains, lookup, flatten, distinct, slice, concat, reverse, sort, zipmap, toset, alltrue, anytrue16
Type conversiontostring, tonumber, tobool3
Mathmin, max, abs, ceil, floor5
Encodingjsonencode, jsondecode, base64encode, base64decode, yamlencode, yamldecode, urlencode, sha256, md59
CIDR / networkingcidrsubnet, cidrhost, cidrnetmask, cidrprefix4
Date / timetimestamp, formatdate2
Filesystemfileset1
Miscuuid, range2
Total59

Common mistakes

All built-in functions are evaluated at compile time from Resolved<T> values. You cannot pass a Pending<T> value (a resource output reference) to a function — lower(unit.rds.db.identifier) is a compile error. Apply functions to inputs and locals only; for pending values, use .apply() chains in the generated code.
cidrsubnet is the most commonly needed networking function. cidrsubnet("10.0.0.0/16", 4, 2) produces the 3rd subnet (index 2) carved from the /16 with a /20 prefix — useful for generating per-AZ subnet CIDRs in for_each or count blocks without hardcoding each value.

Run it

ubx validate   # evaluates all functions at compile time
ubx plan       # requires AWS credentials

What you learned

55 built-in functions are available across 8 categories — all evaluated at compile time
Functions cannot accept Pending<T> values — only Resolved<T> inputs and locals
Functions compose naturally in local blocks and resource attributes

Next steps

Cross-stack same-repo

Reference outputs between stacks in the same repository

Locals

Where functions are most commonly used