->> Day-11 AWS Terraform Functions - Part 1
Source: Dev.to
lower
Converts all cased letters in the given string to lowercase. This function uses Unicode’s definition of letters and of upper‑ and lowercase.
lower("HELLO")
# => "hello"
replace
Searches a given string for a substring and replaces each occurrence with a replacement string.
replace("1 + 2 + 3", "+", "-")
# => "1 - 2 - 3"
replace("hello world", "/w.*d/", "everybody")
# => "hello everybody"
substr
Extracts a substring from a given string by offset and (maximum) length.
substr("hello world", 1, 4)
# => "ello"
split
Produces a list by dividing a given string at all occurrences of a separator.
split(",", "foo,bar,baz")
# => [
# "foo",
# "bar",
# "baz",
# ]
split(",", "foo")
# => [
# "foo",
# ]
split(",", "")
# => [
# "",
# ]
merge
Takes an arbitrary number of maps or objects and returns a single map/object that contains a merged set of elements from all arguments. If the same key appears in multiple arguments, the later argument takes precedence.
merge({a = "b", c = "d"}, {e = "f", c = "z"})
# => {
# "a" = "b"
# "c" = "z"
# "e" = "f"
# }
merge({a = "b"}, {a = [1, 2], c = "z"}, {d = 3})
# => {
# "a" = [
# 1,
# 2,
# ]
# "c" = "z"
# "d" = 3
# }
lookup
Retrieves the value of a single element from a map given its key. If the key does not exist, the provided default value is returned.
lookup({a = "ay", b = "bee"}, "a", "what?")
# => "ay"
lookup({a = "ay", b = "bee"}, "c", "what?")
# => "what?"