Functions#
Orchard exposes 56 functions in every expression — variable defaults,
provider configs, component inputs, action attributes, scenario outputs,
component outputs, and teardown bodies. All names use lowercase compound
words with no separators (jsonencode, timeadd, timeseries, …).
Functions marked with (impure) may return different values on each call. That’s intentional — scenarios are single-shot imperative runs, not convergent plans.
Collections#
concat#
concat(lists...) → listConcatenate two or more lists into one.
| Parameter | Type | Description |
|---|---|---|
lists... | list | Variadic. |
concat(["a"], ["b", "c"])→ ["a", "b", "c"]
contains#
contains(list, value) → boolCheck whether a list or set contains a given value.
| Parameter | Type | Description |
|---|---|---|
list | list | |
value | any |
distinct#
distinct(list) → listRemove duplicate elements from a list.
| Parameter | Type | Description |
|---|---|---|
list | list |
element#
element(list, index) → anyReturn the element at the given index in a list.
| Parameter | Type | Description |
|---|---|---|
list | list | |
index | number |
keys#
keys(map) → list(string)Return the keys of a map as a list.
| Parameter | Type | Description |
|---|---|---|
map | map |
length#
length(collection) → numberReturn the number of elements in a collection.
Works on lists, maps, and tuples. Use strlen for string length.
| Parameter | Type | Description |
|---|---|---|
collection | `list | map |
lookup#
lookup(map, key, default) → anyLook up a key in a map with a default fallback.
| Parameter | Type | Description |
|---|---|---|
map | map | |
key | string | |
default | any |
merge#
merge(maps...) → mapMerge two or more maps. Later keys override earlier ones.
| Parameter | Type | Description |
|---|---|---|
maps... | map | Variadic. |
range#
range(args...) → list(number)Generate a list of numbers.
| Parameter | Type | Description |
|---|---|---|
args... | number | Variadic. |
range(3)→ [0, 1, 2]
reverse#
reverse(list) → listReverse the order of elements in a list.
| Parameter | Type | Description |
|---|---|---|
list | list |
slice#
slice(list, start, end) → listExtract a contiguous sub-list.
| Parameter | Type | Description |
|---|---|---|
list | list | |
start | number | |
end | number |
sort#
sort(list) → list(string)Sort a list of strings lexicographically.
| Parameter | Type | Description |
|---|---|---|
list | list(string) |
values#
values(map) → listReturn the values of a map as a list.
| Parameter | Type | Description |
|---|---|---|
map | map |
zipmap#
zipmap(keys, values) → mapConstruct a map from a list of keys and a list of values.
| Parameter | Type | Description |
|---|---|---|
keys | list(string) | |
values | list |
Encoding#
csvdecode#
csvdecode(str) → list(map(string))Decode a CSV string into a list of maps (first row = headers).
| Parameter | Type | Description |
|---|---|---|
str | string |
jsondecode#
jsondecode(str) → anyDecode a JSON string into a value.
| Parameter | Type | Description |
|---|---|---|
str | string |
jsonencode#
jsonencode(value) → stringEncode a value as a JSON string.
| Parameter | Type | Description |
|---|---|---|
value | any |
jsonencode({name = "alice", age = 30})→ "{\"name\":\"alice\",\"age\":30}"
Environment#
env (impure)#
env(name) → stringRead an environment variable by name.
Returns an empty string when the variable is unset, matching shell convention. Values read via env() may appear in run records — use for connection strings and config, not raw secrets.
| Parameter | Type | Description |
|---|---|---|
name | string | Environment variable name. |
env("DATABASE_URL")→ "postgres://localhost/mydb"
env("UNSET_VAR")→ ""
Identity#
uuid (impure)#
uuid() → stringGenerate a random v4 UUID string.
Each call produces a new value. Use for primary keys, correlation IDs, or any field that needs a unique identifier.
uuid()→ "a3f29e5b-1234-4abc-9def-0123456789ab"
Math#
abs#
abs(n) → numberReturn the absolute value of a number.
| Parameter | Type | Description |
|---|---|---|
n | number |
ceil#
ceil(n) → numberRound a number up to the nearest integer.
| Parameter | Type | Description |
|---|---|---|
n | number |
floor#
floor(n) → numberRound a number down to the nearest integer.
| Parameter | Type | Description |
|---|---|---|
n | number |
log#
log(n, base) → numberReturn the logarithm of a number in a given base.
| Parameter | Type | Description |
|---|---|---|
n | number | |
base | number |
max#
max(numbers...) → numberReturn the largest of the given numbers.
| Parameter | Type | Description |
|---|---|---|
numbers... | number | Variadic. |
min#
min(numbers...) → numberReturn the smallest of the given numbers.
| Parameter | Type | Description |
|---|---|---|
numbers... | number | Variadic. |
pow#
pow(base, exponent) → numberReturn base raised to the power of exponent.
| Parameter | Type | Description |
|---|---|---|
base | number | |
exponent | number |
signum#
signum(n) → numberReturn -1, 0, or 1 depending on the sign of a number.
| Parameter | Type | Description |
|---|---|---|
n | number |
Regex#
regex#
regex(pattern, str) → string | list(string)Apply a regular expression to a string and return the first match.
| Parameter | Type | Description |
|---|---|---|
pattern | string | |
str | string |
regexall#
regexall(pattern, str) → list(string) | list(list(string))Apply a regular expression to a string and return all matches.
| Parameter | Type | Description |
|---|---|---|
pattern | string | |
str | string |
Sets#
setintersection#
setintersection(sets...) → setReturn elements common to all given sets.
| Parameter | Type | Description |
|---|---|---|
sets... | set | Variadic. |
setproduct#
setproduct(sets...) → set(tuple)Compute the Cartesian product of the given sets.
| Parameter | Type | Description |
|---|---|---|
sets... | set | Variadic. |
setsubtract#
setsubtract(a, b) → setReturn elements in the first set that are not in the second.
| Parameter | Type | Description |
|---|---|---|
a | set | |
b | set |
setunion#
setunion(sets...) → setReturn the union of all given sets.
| Parameter | Type | Description |
|---|---|---|
sets... | set | Variadic. |
Strings#
chomp#
chomp(str) → stringRemove trailing newlines from a string.
| Parameter | Type | Description |
|---|---|---|
str | string |
format#
format(format, args...) → stringFormat a string using printf-style verbs.
| Parameter | Type | Description |
|---|---|---|
format | string | |
args... | any | Variadic. |
format("hello %s, you are %d", "alice", 30)→ "hello alice, you are 30"
formatlist#
formatlist(format, args...) → list(string)Format each element of a list using printf-style verbs.
| Parameter | Type | Description |
|---|---|---|
format | string | |
args... | any | Variadic. |
join#
join(separator, list) → stringJoin a list of strings with a separator.
| Parameter | Type | Description |
|---|---|---|
separator | string | |
list | list(string) |
join(", ", ["a", "b", "c"])→ "a, b, c"
lower#
lower(str) → stringConvert a string to lowercase.
| Parameter | Type | Description |
|---|---|---|
str | string |
lower("HELLO")→ "hello"
replace#
replace(str, old, new) → stringReplace all occurrences of a substring.
| Parameter | Type | Description |
|---|---|---|
str | string | |
old | string | |
new | string |
split#
split(separator, str) → list(string)Split a string by a separator.
| Parameter | Type | Description |
|---|---|---|
separator | string | |
str | string |
split(",", "a,b,c")→ ["a", "b", "c"]
strlen#
strlen(str) → numberReturn the length of a string in characters.
Use length for collections (lists, maps, tuples). strlen is for strings only.
| Parameter | Type | Description |
|---|---|---|
str | string |
substr#
substr(str, offset, length) → stringExtract a substring by offset and length.
| Parameter | Type | Description |
|---|---|---|
str | string | |
offset | number | |
length | number |
title#
title(str) → stringConvert a string to title case.
| Parameter | Type | Description |
|---|---|---|
str | string |
title("hello world")→ "Hello World"
trim#
trim(str, cutset) → stringRemove leading and trailing characters from a string.
| Parameter | Type | Description |
|---|---|---|
str | string | |
cutset | string | Characters to remove. |
trimprefix#
trimprefix(str, prefix) → stringRemove a prefix from the start of a string.
| Parameter | Type | Description |
|---|---|---|
str | string | |
prefix | string |
trimspace#
trimspace(str) → stringRemove leading and trailing whitespace from a string.
| Parameter | Type | Description |
|---|---|---|
str | string |
trimsuffix#
trimsuffix(str, suffix) → stringRemove a suffix from the end of a string.
| Parameter | Type | Description |
|---|---|---|
str | string | |
suffix | string |
upper#
upper(str) → stringConvert a string to uppercase.
| Parameter | Type | Description |
|---|---|---|
str | string |
upper("hello")→ "HELLO"
Time#
formatdate#
formatdate(format, timestamp) → stringFormat a timestamp using a format string.
Uses HCL’s format spec: YYYY (year), MM (month), DD (day), hh (hour), mm (minute), ss (second).
| Parameter | Type | Description |
|---|---|---|
format | string | |
timestamp | string | RFC3339 timestamp. |
formatdate("YYYY-MM-DD", "2026-04-20T12:30:00Z")→ "2026-04-20"
now (impure)#
now() → stringReturn the current UTC time as an RFC3339 string.
Evaluated at expression-evaluation time. Two now() calls in the same action body may differ by microseconds.
now()→ "2026-04-20T12:00:00Z"
timeadd#
timeadd(timestamp, duration) → stringAdd a Go duration to a timestamp.
| Parameter | Type | Description |
|---|---|---|
timestamp | string | RFC3339 timestamp. |
duration | string | Go duration (e.g. “6h”, “30m”). |
timeadd("2026-01-01T00:00:00Z", "24h")→ "2026-01-02T00:00:00Z"
timerandom (impure)#
timerandom(start, end) → stringReturn a random timestamp between start and end.
| Parameter | Type | Description |
|---|---|---|
start | string | RFC3339 timestamp (inclusive). |
end | string | RFC3339 timestamp (exclusive). |
timerandom(timesub(now(), "30d"), now())timesequence (impure)#
timesequence(start, end, min_interval, max_interval...) → list(string)Generate timestamps stepping by random intervals between min and max.
Produces timestamps from start until end is reached. With only min_interval, steps are evenly spaced. With both min and max, each step is randomised within the range. Capped at 100,000 entries.
| Parameter | Type | Description |
|---|---|---|
start | string | RFC3339 timestamp. |
end | string | RFC3339 timestamp. |
min_interval | string | Minimum step duration. |
max_interval... | string | Maximum step duration (optional). |
timesequence(timesub(now(), "30d"), now(), "1d", "5d")timeseries#
timeseries(start, end, count) → list(string)Distribute exactly N timestamps evenly between start and end.
First entry is start, last is end, intermediate points are equidistant. Use timesequence for interval-based generation.
| Parameter | Type | Description |
|---|---|---|
start | string | RFC3339 timestamp. |
end | string | RFC3339 timestamp. |
count | number | Number of timestamps to generate. |
timeseries(timesub(now(), "90d"), now(), 10)→ ["2026-01-20T...", ..., "2026-04-20T..."]
timesub#
timesub(timestamp, duration) → stringSubtract a duration from a timestamp.
Supports extended durations: d (days = 24h) and w (weeks = 7d) on top of Go’s standard units.
| Parameter | Type | Description |
|---|---|---|
timestamp | string | RFC3339 timestamp. |
duration | string | Duration (e.g. “30d”, “2w”, “6h”). |
timesub("2026-04-20T00:00:00Z", "7d")→ "2026-04-13T00:00:00Z"
timeunix#
timeunix(timestamp) → numberConvert a timestamp to Unix epoch seconds.
| Parameter | Type | Description |
|---|---|---|
timestamp | string | RFC3339 timestamp. |
timeunix("2026-01-01T00:00:00Z")→ 1767225600