03 - Terraform Function

最後更新: 2023-07-13

目錄

  • String Functions
  • Time Functions

 


String Functions

 

join(separator, list)

大小寫

lower("HELLO")
upper("hello")
title("hello world")

Hello World

trimspace("  hello\n\n")
# spaces, tabs, newline characters, and various other space-like characters.

trimsuffix("helloworld", "world")
hello

trimprefix("helloworld", "hello")
world

trim(string, str_character_set)
# Every occurrence of a character in the second argument is removed from the start and end of the string specified in the first argument.

substr(string, offset, length)
substr extracts a substring from a given string by offset and (maximum) length.

split(separator, string)

replace(string, substring, replacement)
If substring is wrapped in forward slashes, it is treated as a regex

startswith(string, prefix)
endswith(string, suffix)
# returns true if the first string ends with that exact suffix.

regex(pattern, string)
If the pattern has no capture groups at all, the result is a single string covering the substring matched by the pattern as a whole.
If the pattern has one or more unnamed capture groups, the result is a list of the captured substrings in the same order as the definition of the capture groups.
regexall(pattern, string)     # returns a list of whatever type regex would've returned

 


Time Functions

 

# returns a UTC timestamp string in RFC 3339 format
# "2023-07-11T04:55:20Z"
timestamp()

# "11:12pm"
formatdate("HH:mmaa", "2018-01-02T23:12:01Z")

# "2023-07-11T12:59:16Z"
timeadd(timestamp(), "8h")

# 應用
formatdate("YYMMDDHHmm", timeadd(timestamp(), "8h"))

 

 

 

Creative Commons license icon Creative Commons license icon