functions
Powerpipe supports the following Terraform-compatible HCL functions:
Numeric Functions
Function | Description |
---|---|
abs | Returns the absolute value of a number. |
ceil | Returns the smallest integer value greater than or equal to a given number. |
floor | Returns the largest integer value less than or equal to a given number. |
log | Returns the natural logarithm of a number. |
max | Returns the maximum value from a list of numbers. |
min | Returns the minimum value from a list of numbers. |
parseint | Parses a string as an integer. |
pow | Returns the result of raising a number to the power of another. |
signum | Returns -1, 0, or 1 depending on the sign of a number. |
sum | Returns the sum of a list of numbers. |
String Functions
Function | Description |
---|---|
chomp | Removes trailing newline characters from a string. |
endswith | Checks if a string ends with a specified suffix. |
format | Formats a string using printf-style formatting. |
formatlist | Formats a list of values into a string using printf-style formatting. |
indent | Indents a string by a specified number of spaces. |
join | Joins elements of a list into a string with a delimiter. |
lower | Converts a string to lowercase. |
regex | Searches a string using a regular expression. |
regexall | Searches a string using a regular expression and returns all matches. |
replace | Replaces occurrences of a substring with another string. |
split | Splits a string into a list of substrings. |
startswith | Checks if a string starts with a specified prefix. |
strcontains | Checks if a string contains another substring. |
strrev | Reverses a string. |
substr | Returns a substring from a string. |
title | Converts the first character of each word in a string to uppercase. |
trim | Trim whitespace from a string |
trimprefix | Trim a prefix from a string |
trimspace | Trim leading and trailing whitespace |
trimsuffix | Trim a suffix from a string |
upper | Converts a string to uppercase. |
Collection Functions
Function | Description |
---|---|
alltrue | Returns true if all elements in a list are true. |
anytrue | Returns true if any element in a list is true. |
chunklist | Splits a list into chunks of a specified size. |
coalesce | Returns the first non-null value in a list. |
coalescelist | Returns the first non-empty list in a list of lists. |
compact | Removes null and empty string elements from a list. |
concat | Concatenates multiple lists into one list. |
contains | Checks if a value is in a list, set, or map. |
distinct | Returns a new list with duplicate elements removed. |
element | Returns the element at a specified index in a list. |
flatten | Flattens a list of lists into a single list. |
index | Returns the index of a value in a list. |
keys | Returns the keys of a map as a list. |
length | Returns the length of a string, list, or map. |
list | Creates a list from the arguments. |
lookup | Looks up a value in a map using a key. |
map | Creates a map from a list of key-value pairs. |
matchkeys | Returns a map with only the specified keys. |
merge | Merges maps together. |
one | Returns true if only one element in a list is true. |
range | Generates a sequence of numbers. |
reverse | Reverses the order of elements in a list. |
setintersection | Returns the intersection of two sets. |
setproduct | Returns the Cartesian product of two or more sets. |
setsubtract | Returns the difference of two sets. |
setunion | Returns the union of two or more sets. |
slice | Extracts a subsequence from a list. |
sort | Sorts a list of strings or numbers. |
sum | Returns the sum of a list of numbers. |
transpose | Transpose a list of lists |
values | Returns the values of a map as a list. |
zipmap | Creates a map from two lists. |
Encoding Functions
Function | Description |
---|---|
base64decode | Decodes a base64-encoded string. |
base64encode | Encodes a string to base64. |
base64gzip | Compresses and then base64-encodes a string. |
csvdecode | Decodes a CSV string into a list of maps. |
jsondecode | Decodes a JSON string into a map or list. |
jsonencode | Encodes a value as a JSON string. |
textdecodebase64 | Decodes a base64-encoded string. |
textencodebase64 | Encodes a string to base64. |
urlencode | URL-encodes a string. |
yamldecode | Decodes a YAML string into a map or list. |
yamlencode | Encodes a value as a YAML string. |
Filesystem Functions
Function | Description |
---|---|
abspath | Returns the absolute path of a file or directory. |
basename | Returns the last element of a path. |
dirname | Returns the directory part of a path. |
pathexpand | Expands the tilde (~) in a file path. |
file | Reads the contents of a file. |
fileexists | Returns true if a file exists. |
fileset | Returns a set of files matching a glob pattern. |
filebase64 | Reads the contents of a file and base64-encodes it. |
Date and Time Functions
Function | Description |
---|---|
formatdate | Formats a timestamp into a string. |
timeadd | Adds a duration to a timestamp. |
timecmp | Compares two timestamps. |
timestamp | Returns the current timestamp. |
Hash and Crypto Functions
Function | Description |
---|---|
base64sha256 | Computes the SHA-256 hash of a string and base64-encodes the result. |
base64sha512 | Computes the SHA-512 hash of a string and base64-encodes the result. |
bcrypt | Hashes a string using the bcrypt algorithm. |
filebase64sha256 | Reads the contents of a file, calculates the SHA256 hash, and base64-encodes it. |
filebase64sha512 | Reads the contents of a file, calculates the SHA512 hash, and base64-encodes it. |
filemd5 | Reads the contents of a file and calculates the MD5 hash. |
filesha1 | Reads the contents of a file and calculates the SHA1 hash. |
filesha256 | Reads the contents of a file and calculates the SHA256 hash. |
filesha512 | Reads the contents of a file and calculates the SHA512 hash. |
md5 | Computes the MD5 hash of a string. |
rsadecrypt | Decrypts data using an RSA private key. |
sha1 | Computes the SHA-1 hash of a string. |
sha256 | Computes the SHA-256 hash of a string. |
sha512 | Computes the SHA-512 hash of a string. |
uuid | Generates a random UUID. |
uuidv5 | Generates a UUID using a name and namespace. |
IP Network Functions
Function | Description |
---|---|
cidrhost | Calculates the IP address of a host in a CIDR block. |
cidrnetmask | Calculates the network mask of a CIDR block. |
cidrsubnet | Calculates a subnet address within a CIDR block. |
cidrsubnets | Splits a CIDR block into multiple subnets. |
Type Conversion Functions
Function | Description |
---|---|
can | Checks if a value has a specific attribute or method. |
nonsensitive | Marks a value as non-sensitive, allowing it to be displayed in logs. |
sensitive | Marks a value as sensitive to avoid exposing sensitive information. |
tobool | Converts a value to a boolean. |
tolist | Converts a value to a list. |
tomap | Converts a value to a map. |
tonumber | Converts a string to a number. |
toset | Converts a list to a set. |
tostring | Converts a value to a string. |
try | Attempts to evaluate an expression and returns a default value on failure. |