The join function combines a list of strings into one string, using a specified separator between each element.
Click to reveal answer
beginner
How does the split function work in Terraform?
The split function breaks a single string into a list of strings, using a specified separator to decide where to split.
Click to reveal answer
beginner
Explain the purpose of the format function in Terraform.
The format function creates a formatted string by inserting values into placeholders inside a template string, similar to filling blanks in a sentence.
Click to reveal answer
beginner
Example: What is the result of join(",", ["apple", "banana", "cherry"])?
The result is the string "apple,banana,cherry", which joins the list elements with commas.
Click to reveal answer
beginner
Example: What does split(",", "red,green,blue") return?
It returns the list ["red", "green", "blue"] by splitting the string at each comma.
Click to reveal answer
Which Terraform function would you use to combine a list of strings into one string?
Asplit
Bjoin
Cformat
Dconcat
✗ Incorrect
The join function combines list elements into a single string with a separator.
What does the split function return when given a string and a separator?
AA list of strings
BA number
CA single string
DA boolean
✗ Incorrect
split breaks a string into a list of strings based on the separator.
How does the format function work in Terraform?
AIt splits strings into lists
BIt joins lists into strings
CIt inserts values into a template string
DIt converts strings to numbers
✗ Incorrect
format creates a string by placing values into placeholders.
What is the output of join("-", ["a", "b", "c"])?
A"a,b,c"
B"abc"
C["a", "b", "c"]
D"a-b-c"
✗ Incorrect
The list elements are joined with dashes to form "a-b-c".
If you run split(":", "key:value"), what do you get?
A["key", "value"]
B"key:value"
C"key"
D[":", "key", "value"]
✗ Incorrect
The string is split at the colon into a list with two elements.
Describe how you would use Terraform string functions to convert a list of strings into a single comma-separated string.
Think about combining list items with a character between them.
You got /4 concepts.
Explain how the format function helps in creating dynamic strings in Terraform configurations.
Imagine writing a sentence where you fill in names or numbers dynamically.
You got /4 concepts.
Practice
(1/5)
1. What does the Terraform function join(",", ["a", "b", "c"]) return?
easy
A. "a,b,c"
B. ["a", "b", "c"]
C. "a b c"
D. "abc"
Solution
Step 1: Understand the join function
The join function combines list elements into a single string using the given separator.
Step 2: Apply join with separator ','
Joining ["a", "b", "c"] with "," results in the string "a,b,c".
Final Answer:
"a,b,c" -> Option A
Quick Check:
join with comma = "a,b,c" [OK]
Hint: Join combines list items with separator into one string [OK]
Common Mistakes:
Confusing join output with original list
Using space instead of comma as separator
Expecting a list instead of a string
2. Which of the following is the correct syntax to split the string "one,two,three" into a list using Terraform?
easy
A. format(",", "one,two,three")
B. split("one,two,three", ",")
C. split(",", "one,two,three")
D. join(",", "one,two,three")
Solution
Step 1: Recall split function syntax
The split function takes the separator first, then the string to split.
Step 2: Match correct argument order
Only split(",", "one,two,three") matches the correct syntax.
Hint: split(separator, string) order matters in Terraform [OK]
Common Mistakes:
Swapping arguments order in split
Using join instead of split
Using format instead of split
3. What is the output of this Terraform expression?
format("Hello %s, you have %d messages", "Alice", 5)
medium
A. "Hello Alice, you have 5 messages"
B. "Hello Alice, you have %d messages"
C. "Hello %s, you have %d messages"
D. "Hello %s, you have 5 messages"
Solution
Step 1: Understand format placeholders
%s is replaced by string, %d by integer in order.
Step 2: Replace placeholders with arguments
"Alice" replaces %s, 5 replaces %d, producing "Hello Alice, you have 5 messages".
Final Answer:
"Hello Alice, you have 5 messages" -> Option A
Quick Check:
format with %s and %d = formatted string [OK]
Hint: format replaces %s and %d placeholders in order [OK]
Common Mistakes:
Not replacing placeholders
Mixing up %s and %d types
Expecting original string without substitution
4. Identify the error in this Terraform code snippet:
locals {
parts = split(",", "apple,banana,orange")
result = join(";", parts)
message = format("Fruits: %s", result)
}
medium
A. join separator should be a list, not a string
B. split function arguments are reversed
C. format placeholder %s cannot accept a string
D. No error, code is correct
Solution
Step 1: Check split function usage
split separator and string are correctly ordered.
Step 2: Check join and format usage
join uses string separator ";" correctly; format uses %s for string correctly.
Final Answer:
No error, code is correct -> Option D
Quick Check:
split, join, format used correctly = No error, code is correct [OK]
Hint: Check argument order and placeholder types carefully [OK]
Common Mistakes:
Swapping split arguments
Using wrong placeholder in format
Passing wrong types to join
5. You have a list of IP addresses: ["10.0.0.1", "10.0.0.2", "10.0.0.3"]. You want to create a single string with these IPs separated by commas, but enclosed in square brackets like this: [10.0.0.1,10.0.0.2,10.0.0.3] Which Terraform expression achieves this?
hard
A. join(",", format("[%s]", ["10.0.0.1", "10.0.0.2", "10.0.0.3"]))
B. format("[%s]", join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"]))
C. split(",", format("[%s]", join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"])))
D. format(join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"]), "[%s]")
Solution
Step 1: Join IP list with commas
Using join(",", [...]) creates "10.0.0.1,10.0.0.2,10.0.0.3".
Step 2: Use format to add square brackets
Wrapping the joined string with format("[%s]", ...) adds brackets around it.
Final Answer:
format("[%s]", join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"])) -> Option B
Quick Check:
join then format = format("[%s]", join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"])) [OK]
Hint: Join first, then format to add brackets [OK]
Common Mistakes:
Trying to format before join
Using split instead of join
Incorrect argument order in format
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.