Bird
Raised Fist0
Terraformcloud~20 mins

String functions (join, split, format) in Terraform - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Terraform String Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate
2:00remaining
What is the output of this Terraform expression using join and split?
Given the Terraform expression:
join(",", split("-", "a-b-c-d"))

What is the resulting string?
Terraform
join(",", split("-", "a-b-c-d"))
A"a,b,c,d"
B"a-b-c-d"
C"a,b-c,d"
D"a,b,c-d"
Attempts:
2 left
💡 Hint
Think about how split breaks the string and how join combines the list.
❓ Configuration
intermediate
2:00remaining
What is the value of variable 'result' after this Terraform format call?
Consider this Terraform code:
variable "name" { default = "cloud" }
variable "count" { default = 3 }

output "result" {
  value = format("%s-%d", var.name, var.count)
}

What is the output value of 'result'?
Terraform
format("%s-%d", var.name, var.count)
A"cloud-3"
B"3-cloud"
C"cloud-"
D"%s-%d"
Attempts:
2 left
💡 Hint
Look at the order of arguments in format and their types.
🧠 Conceptual
advanced
2:00remaining
Which option correctly splits a comma-separated string into a list in Terraform?
You have a string variable:
variable "csv" { default = "red,green,blue" }

Which expression produces the list ["red", "green", "blue"]?
Aformat("%s", var.csv)
Bjoin(",", var.csv)
Csplit(",", var.csv)
Dsplit(";", var.csv)
Attempts:
2 left
💡 Hint
Splitting uses the delimiter to break the string into parts.
❓ security
advanced
2:00remaining
What is the risk of using format with user input without validation in Terraform?
If you use format("User: %s", var.user_input) directly in resource names, what could happen?
AThere is no risk; format is safe for all inputs
BTerraform will automatically sanitize the input to prevent errors
CThe format function will throw an error if input is unsafe
DResource names might contain invalid characters causing deployment failure
Attempts:
2 left
💡 Hint
Think about what happens if user input has spaces or special symbols.
❓ Architecture
expert
3:00remaining
Which Terraform expression produces a single string from a list with a custom separator and prefix?
Given a list variable:
variable "items" { default = ["one", "two", "three"] }

Which expression produces the string "Items: one | two | three"?
Ajoin(" | ", format("Items: %s", var.items))
Bformat("Items: %s", join(" | ", var.items))
Cformat("Items: %s", split(" | ", var.items))
Djoin("Items: ", var.items)
Attempts:
2 left
💡 Hint
Use join to combine list elements, then format to add prefix.

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

  1. Step 1: Understand the join function

    The join function combines list elements into a single string using the given separator.
  2. Step 2: Apply join with separator ','

    Joining ["a", "b", "c"] with "," results in the string "a,b,c".
  3. Final Answer:

    "a,b,c" -> Option A
  4. 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

  1. Step 1: Recall split function syntax

    The split function takes the separator first, then the string to split.
  2. Step 2: Match correct argument order

    Only split(",", "one,two,three") matches the correct syntax.
  3. Final Answer:

    split(",", "one,two,three") -> Option C
  4. Quick Check:

    split(separator, string) = split(",", "one,two,three") [OK]
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

  1. Step 1: Understand format placeholders

    %s is replaced by string, %d by integer in order.
  2. Step 2: Replace placeholders with arguments

    "Alice" replaces %s, 5 replaces %d, producing "Hello Alice, you have 5 messages".
  3. Final Answer:

    "Hello Alice, you have 5 messages" -> Option A
  4. 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

  1. Step 1: Check split function usage

    split separator and string are correctly ordered.
  2. Step 2: Check join and format usage

    join uses string separator ";" correctly; format uses %s for string correctly.
  3. Final Answer:

    No error, code is correct -> Option D
  4. 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

  1. Step 1: Join IP list with commas

    Using join(",", [...]) creates "10.0.0.1,10.0.0.2,10.0.0.3".
  2. Step 2: Use format to add square brackets

    Wrapping the joined string with format("[%s]", ...) adds brackets around it.
  3. Final Answer:

    format("[%s]", join(",", ["10.0.0.1", "10.0.0.2", "10.0.0.3"])) -> Option B
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard