0
0
Terraformcloud~20 mins

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

Choose your learning style9 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.