0
0
Terraformcloud~20 mins

For expressions for transformation in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
For Expressions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding For Expressions Output
Given the Terraform expression [for i in [1, 2, 3] : i * 2], what is the resulting list?
Terraform
[for i in [1, 2, 3] : i * 2]
A[2, 4, 6]
B[1, 2, 3]
C[1, 4, 9]
D[3, 6, 9]
Attempts:
2 left
💡 Hint
Each element is multiplied by 2.
Configuration
intermediate
1:30remaining
Filtering with For Expressions
What is the output of this Terraform expression?
[for n in [1, 2, 3, 4] : n if n % 2 == 0]
Terraform
[for n in [1, 2, 3, 4] : n if n % 2 == 0]
A[1, 3]
B[2, 4]
C[1, 2, 3, 4]
DSyntaxError
Attempts:
2 left
💡 Hint
Only even numbers are included.
Architecture
advanced
2:00remaining
Transforming Map Values with For Expressions
Given this Terraform map:
{"a" = 1, "b" = 2, "c" = 3}
What is the output of this expression?
{for k, v in {"a" = 1, "b" = 2, "c" = 3} : k => v * v}
Terraform
{for k, v in {"a" = 1, "b" = 2, "c" = 3} : k => v * v}
A[1, 4, 9]
B{"a" = 2, "b" = 3, "c" = 4}
C{"a" = 1, "b" = 4, "c" = 9}
DSyntaxError
Attempts:
2 left
💡 Hint
Each value is squared, keys remain the same.
service_behavior
advanced
2:00remaining
For Expressions with Nested Lists
What is the output of this Terraform expression?
[for sublist in [[1, 2], [3, 4]] : [for n in sublist : n * 10]]
Terraform
[for sublist in [[1, 2], [3, 4]] : [for n in sublist : n * 10]]
A[[10, 20], [30, 40]]
B[10, 20, 30, 40]
C[[1, 2], [3, 4]]
DTypeError
Attempts:
2 left
💡 Hint
Each inner list element is multiplied by 10.
security
expert
2:30remaining
For Expressions and Sensitive Data Handling
Consider a Terraform variable var.passwords = ["pass1", "pass2"] marked as sensitive. Which for expression correctly creates a new list masking each password with asterisks of the same length, without exposing the original passwords in logs or state?
A[for p in var.passwords : substr(p, 0, 2)]
B[for p in var.passwords : p]
C[for p in var.passwords : "*****"]
D[for p in var.passwords : "*" * length(p)]
Attempts:
2 left
💡 Hint
Mask length should match original password length without revealing content.