functions

Flowpipe supports the following Terraform-compatible HCL functions:

Numeric Functions

FunctionDescription
absReturns the absolute value of a number.
ceilReturns the smallest integer value greater than or equal to a given number.
floorReturns the largest integer value less than or equal to a given number.
logReturns the natural logarithm of a number.
maxReturns the maximum value from a list of numbers.
minReturns the minimum value from a list of numbers.
parseintParses a string as an integer.
powReturns the result of raising a number to the power of another.
signumReturns -1, 0, or 1 depending on the sign of a number.
sumReturns the sum of a list of numbers.

String Functions

FunctionDescription
chompRemoves trailing newline characters from a string.
endswithChecks if a string ends with a specified suffix.
formatFormats a string using printf-style formatting.
formatlistFormats a list of values into a string using printf-style formatting.
indentIndents a string by a specified number of spaces.
joinJoins elements of a list into a string with a delimiter.
lowerConverts a string to lowercase.
regexSearches a string using a regular expression.
regexallSearches a string using a regular expression and returns all matches.
replaceReplaces occurrences of a substring with another string.
splitSplits a string into a list of substrings.
startswithChecks if a string starts with a specified prefix.
strcontainsChecks if a string contains another substring.
strrevReverses a string.
substrReturns a substring from a string.
titleConverts the first character of each word in a string to uppercase.
trimTrim whitespace from a string
trimprefixTrim a prefix from a string
trimspaceTrim leading and trailing whitespace
trimsuffixTrim a suffix from a string
upperConverts a string to uppercase.

Collection Functions

FunctionDescription
alltrueReturns true if all elements in a list are true.
anytrueReturns true if any element in a list is true.
chunklistSplits a list into chunks of a specified size.
coalesceReturns the first non-null value in a list.
coalescelistReturns the first non-empty list in a list of lists.
compactRemoves null and empty string elements from a list.
concatConcatenates multiple lists into one list.
containsChecks if a value is in a list, set, or map.
distinctReturns a new list with duplicate elements removed.
elementReturns the element at a specified index in a list.
flattenFlattens a list of lists into a single list.
indexReturns the index of a value in a list.
keysReturns the keys of a map as a list.
lengthReturns the length of a string, list, or map.
listCreates a list from the arguments.
lookupLooks up a value in a map using a key.
mapCreates a map from a list of key-value pairs.
matchkeysReturns a map with only the specified keys.
mergeMerges maps together.
oneReturns true if only one element in a list is true.
rangeGenerates a sequence of numbers.
reverseReverses the order of elements in a list.
setintersectionReturns the intersection of two sets.
setproductReturns the Cartesian product of two or more sets.
setsubtractReturns the difference of two sets.
setunionReturns the union of two or more sets.
sliceExtracts a subsequence from a list.
sortSorts a list of strings or numbers.
sumReturns the sum of a list of numbers.
transposeTranspose a list of lists
valuesReturns the values of a map as a list.
zipmapCreates a map from two lists.

Encoding Functions

FunctionDescription
base64decodeDecodes a base64-encoded string.
base64encodeEncodes a string to base64.
base64gzipCompresses and then base64-encodes a string.
csvdecodeDecodes a CSV string into a list of maps.
jsondecodeDecodes a JSON string into a map or list.
jsonencodeEncodes a value as a JSON string.
textdecodebase64Decodes a base64-encoded string.
textencodebase64Encodes a string to base64.
urlencodeURL-encodes a string.
yamldecodeDecodes a YAML string into a map or list.
yamlencodeEncodes a value as a YAML string.

Filesystem Functions

FunctionDescription
abspathReturns the absolute path of a file or directory.
basenameReturns the last element of a path.
dirnameReturns the directory part of a path.
pathexpandExpands the tilde (~) in a file path.
fileReads the contents of a file.
fileexistsReturns true if a file exists.
filesetReturns a set of files matching a glob pattern.
filebase64Reads the contents of a file and base64-encodes it.

Date and Time Functions

FunctionDescription
formatdateFormats a timestamp into a string.
timeaddAdds a duration to a timestamp.
timecmpCompares two timestamps.
timestampReturns the current timestamp.

Hash and Crypto Functions

FunctionDescription
base64sha256Computes the SHA-256 hash of a string and base64-encodes the result.
base64sha512Computes the SHA-512 hash of a string and base64-encodes the result.
bcryptHashes a string using the bcrypt algorithm.
filebase64sha256Reads the contents of a file, calculates the SHA256 hash, and base64-encodes it.
filebase64sha512Reads the contents of a file, calculates the SHA512 hash, and base64-encodes it.
filemd5Reads the contents of a file and calculates the MD5 hash.
filesha1Reads the contents of a file and calculates the SHA1 hash.
filesha256Reads the contents of a file and calculates the SHA256 hash.
filesha512Reads the contents of a file and calculates the SHA512 hash.
md5Computes the MD5 hash of a string.
rsadecryptDecrypts data using an RSA private key.
sha1Computes the SHA-1 hash of a string.
sha256Computes the SHA-256 hash of a string.
sha512Computes the SHA-512 hash of a string.
uuidGenerates a random UUID.
uuidv5Generates a UUID using a name and namespace.

IP Network Functions

FunctionDescription
cidrhostCalculates the IP address of a host in a CIDR block.
cidrnetmaskCalculates the network mask of a CIDR block.
cidrsubnetCalculates a subnet address within a CIDR block.
cidrsubnetsSplits a CIDR block into multiple subnets.

Type Conversion Functions

FunctionDescription
canChecks if a value has a specific attribute or method.
nonsensitiveMarks a value as non-sensitive, allowing it to be displayed in logs.
sensitiveMarks a value as sensitive to avoid exposing sensitive information.
toboolConverts a value to a boolean.
tolistConverts a value to a list.
tomapConverts a value to a map.
tonumberConverts a string to a number.
tosetConverts a list to a set.
tostringConverts a value to a string.
tryAttempts to evaluate an expression and returns a default value on failure.

Flowpipe Functions

FunctionDescription
envGets the value of an environment variable.
error_messageGiven a reference to a step, returns a string containing the first error message.
is_errorGiven a reference to a step, returns `true`` if there are any errors.

env

env returns the value of an environment variable. Be careful when using environment variables, as they are global variables. When writing mod, you should generally use variables or pipeline parameters for passing data into the mod, though you may use env to set a default value.

param "region" {
default = env("AWS_REGION")
}

error_message

Given a reference to a step, error_message will return a string containing the first error message, if any. If there are no errors, it will return an empty string.

step "http" "my_request" {
url = "https://myapi.local/subscribe"
method = "post"
body = jsonencode({
name = param.subscriber
})
error {
ignore = true
}
}
output "error_message" {
value = err_message(step.http.my_request)
}

is_error

Given a reference to a step, is_error returns a boolean true if there are 1 or more errors, or false if there are no errors.

step "http" "my_request" {
url = "https://myapi.local/subscribe"
method = "post"
body = jsonencode({
name = param.subscriber
})
error {
ignore = true
}
}
step "email" "send_it" {
to = param.subscriber
subject = "You have been subscribed"
body = step.http.my_request.response_body
if = !is_error(step.http.my_request)
}