Bake standard library functions

Table of contents

NameDescription
absoluteIf the given number is negative then returns its positive equivalent, or otherwise returns the given number unchanged.
addReturns the sum of the two given numbers.
andApplies the logical AND operation to the given boolean values.
base64decodeDecodes a string containing a base64 sequence.
base64encodeEncodes a string to a base64 sequence.
basenameReturns the last element of a path.
bcryptComputes a hash of the given string using the Blowfish cipher.
byteslenReturns the total number of bytes in the given buffer.
bytessliceExtracts a subslice from the given buffer.
canTries to evaluate the expression given in its first argument.
ceilReturns the smallest whole number that is greater than or equal to the given value.
chompRemoves one or more newline characters from the end of the given string.
chunklistSplits a single list into multiple lists where each has at most the given number of elements.
cidrhostCalculates a full host IP address within a given IP network address prefix.
cidrnetmaskConverts an IPv4 address prefix given in CIDR notation into a subnet mask address.
cidrsubnetCalculates a subnet address within a given IP network address prefix.
cidrsubnetsCalculates many consecutive subnet addresses at once, rather than just a single subnet extension.
coalesceReturns the first of the given arguments that isn't null, or raises an error if there are no non-null arguments.
coalescelistReturns the first of the given sequences that has a length greater than zero.
compactRemoves all empty string elements from the given list of strings.
concatConcatenates together all of the given lists or tuples into a single sequence, preserving the input order.
containsReturns true if the given value is a value in the given list, tuple, or set, or false otherwise.
convertConverts a value to a specified type constraint, using HCL's customdecode extension for type expression support.
csvdecodeParses the given string as Comma Separated Values (as defined by RFC 4180) and returns a map of objects representing the table of data, using the first row as a header row to define the object attributes.
dirnameReturns the directory of a path.
distinctRemoves any duplicate values from the given list, preserving the order of remaining elements.
divideDivides the first given number by the second.
elementReturns the element with the given index from the given list or tuple, applying the modulo operation to the given index if it's greater than the number of elements.
equalReturns true if the two given values are equal, or false otherwise.
flattenTransforms a list, set, or tuple value into a tuple by replacing any given elements that are themselves sequences with a flattened tuple of all of the nested elements concatenated together.
floorReturns the greatest whole number that is less than or equal to the given value.
formatConstructs a string by applying formatting verbs to a series of arguments, using a similar syntax to the C function "printf".
formatdateFormats a timestamp given in RFC 3339 syntax into another timestamp in some other machine-oriented time syntax, as described in the format string.
formatlistConstructs a list of strings by applying formatting verbs to a series of arguments, using a similar syntax to the C function "printf".
greaterthanReturns true if and only if the second number is greater than the first.
greaterthanorequaltoReturns true if and only if the second number is greater than or equal to the first.
hasindexReturns true if if the given collection can be indexed with the given key without producing an error, or false otherwise.
indentAdds a given number of spaces after each newline character in the given string.
indexReturns the element with the given key from the given collection, or raises an error if there is no such element.
indexofFinds the element index for a given value in a list.
intDiscards any fractional portion of the given number.
joinConcatenates together the elements of all given lists with a delimiter, producing a single string.
jsondecodeParses the given string as JSON and returns a value corresponding to what the JSON document describes.
jsonencodeReturns a string containing a JSON representation of the given value.
keysReturns a list of the keys of the given map in lexicographical order.
lengthReturns the number of elements in the given collection.
lessthanReturns true if and only if the second number is less than the first.
lessthanorequaltoReturns true if and only if the second number is less than or equal to the first.
logReturns the logarithm of the given number in the given base.
lookupReturns the value of the element with the given key from the given map, or returns the default value if there is no such element.
lowerReturns the given string with all Unicode letters translated to their lowercase equivalents.
maxReturns the numerically greatest of all of the given numbers.
md5Computes the MD5 hash of a given string and encodes it with hexadecimal digits.
mergeMerges all of the elements from the given maps into a single map, or the attributes from given objects into a single object.
minReturns the numerically smallest of all of the given numbers.
moduloDivides the first given number by the second and then returns the remainder.
multiplyReturns the product of the two given numbers.
negateMultiplies the given number by -1.
notApplies the logical NOT operation to the given boolean value.
notequalReturns false if the two given values are equal, or true otherwise.
orApplies the logical OR operation to the given boolean values.
parseintParses the given string as a number of the given base, or raises an error if the string contains invalid characters.
powReturns the given number raised to the given power (exponentiation).
rangeReturns a list of numbers spread evenly over a particular range.
regexApplies the given regular expression pattern to the given string and returns information about a single match, or raises an error if there is no match.
regex_replaceApplies the given regular expression pattern to the given string and replaces all matches with the given replacement string.
regexallApplies the given regular expression pattern to the given string and returns a list of information about all non-overlapping matches, or an empty list if there are no matches.
replaceReplaces all instances of the given substring in the given string with the given replacement string.
reverseReturns the given string with all of its Unicode characters in reverse order.
reverselistReturns the given list with its elements in reverse order.
rsadecryptDecrypts an RSA-encrypted ciphertext.
sanitizeReplaces all non-alphanumeric characters with a underscore, leaving only characters that are valid for a Bake target name.
sethaselementReturns true if the given set contains the given element, or false otherwise.
setintersectionReturns the intersection of all given sets.
setproductCalculates the cartesian product of two or more sets.
setsubtractReturns the relative complement of the two given sets.
setsymmetricdifferenceReturns the symmetric difference of the two given sets.
setunionReturns the union of all given sets.
sha1Computes the SHA1 hash of a given string and encodes it with hexadecimal digits.
sha256Computes the SHA256 hash of a given string and encodes it with hexadecimal digits.
sha512Computes the SHA512 hash of a given string and encodes it with hexadecimal digits.
signumReturns 0 if the given number is zero, 1 if the given number is positive, or -1 if the given number is negative.
sliceExtracts a subslice of the given list or tuple value.
sortApplies a lexicographic sort to the elements of the given list.
splitProduces a list of one or more strings by splitting the given string at all instances of a given separator substring.
strlenReturns the number of Unicode characters (technically: grapheme clusters) in the given string.
substrExtracts a substring from the given string.
subtractReturns the difference between the two given numbers.
timeaddAdds the duration represented by the given duration string to the given RFC 3339 timestamp string, returning another RFC 3339 timestamp.
timestampReturns a string representation of the current date and time.
titleReplaces one letter after each non-letter and non-digit character with its uppercase equivalent.
trimRemoves consecutive sequences of characters in "cutset" from the start and end of the given string.
trimprefixRemoves the given prefix from the start of the given string, if present.
trimspaceRemoves any consecutive space characters (as defined by Unicode) from the start and end of the given string.
trimsuffixRemoves the given suffix from the start of the given string, if present.
tryVariadic function that tries to evaluate all of is arguments in sequence until one succeeds, in which case it returns that result, or returns an error if none of them succeed.
upperReturns the given string with all Unicode letters translated to their uppercase equivalents.
urlencodeApplies URL encoding to a given string.
uuidv4Generates and returns a Type-4 UUID in the standard hexadecimal string format.
uuidv5Generates and returns a Type-5 UUID in the standard hexadecimal string format.
valuesReturns the values of elements of a given map, or the values of attributes of a given object, in lexicographic order by key or attribute name.
zipmapConstructs a map from a list of keys and a corresponding list of values, which must both be of the same length.

Examples

add

# docker-bake.hcl
target "webapp-dev" {
  dockerfile = "Dockerfile.webapp"
  tags = ["docker.io/username/webapp:latest"]
  args = {
    buildno = "${add(123, 1)}"
  }
}