Terraform
TF CMD Cheatsheet
Quick reference for commonly used TF string functions. Learn how to manipulate strings efficiently in your Terraform configurations with this handy cheatsheet.
Terraform
Cloud
Infrastructure as Code
IaC
DevOps
π TF CMD Cheatsheet: String Functions
| func | output | usage |
|---|---|---|
startswith("hello world", "hello") |
true | |
endswith("hello world", "world") |
true | |
upper("hello") |
HELLO | |
lower("HELLO") |
hello | |
strrev("hello") |
olleh | |
substr("hello world", 1, 4) |
ello | |
title("hello world") |
Hello World | |
trim("?!hello?!", "!?") |
hello | Removes the specified set of characters from the start and end of the given string. |
trimsuffix("helloworld", "world") |
hello | removes the specified suffix from the end of the given string. |
trimprefix("helloworld", "hello") |
world | removes the specified prefix from the start of the given string. |
trimspace(" hello\n\n") |
hello | removes any space characters from the start and end of the given string. |
indent(2, "[\n foo,\n bar,\n]\n") |
"[\n foo,\n bar,\n ]\n" | adds a given number of spaces to the beginnings of all but the first line in a given multi-line string. |
join("-", ["foo", "bar", "baz"]) |
"foo-bar-baz" | produces a string by concatenating all of the elements of the specified list of strings with the specified separator. |
replace("1 + 2 + 3", "+", "-") |
1 - 2 - 3 | searches a given string for another given substring, and replaces each occurrence with a given replacement string. |
split(",", "foo,bar,baz") |
["foo","bar","baz",] | produces a list by dividing a given string at all occurrences of a given separator. |
