Challenge - 5 Problems
For Expressions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1: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]
Attempts:
2 left
💡 Hint
Each element is multiplied by 2.
✗ Incorrect
The for expression iterates over each element and multiplies it by 2, producing [2, 4, 6].
❓ Configuration
intermediate1: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]
Attempts:
2 left
💡 Hint
Only even numbers are included.
✗ Incorrect
The for expression filters to include only numbers divisible by 2, resulting in [2, 4].
❓ Architecture
advanced2:00remaining
Transforming Map Values with For Expressions
Given this Terraform map:
What is the output of this expression?
{"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}Attempts:
2 left
💡 Hint
Each value is squared, keys remain the same.
✗ Incorrect
The for expression creates a new map with the same keys but squares each value.
❓ service_behavior
advanced2: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]]
Attempts:
2 left
💡 Hint
Each inner list element is multiplied by 10.
✗ Incorrect
The outer for expression iterates over sublists, and the inner one multiplies each number by 10, preserving the nested list structure.
❓ security
expert2: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?Attempts:
2 left
💡 Hint
Mask length should match original password length without revealing content.
✗ Incorrect
Option D creates a masked string of asterisks matching the length of each password, avoiding exposure of actual passwords. Option D exposes passwords directly. Option D uses fixed length masking which may reveal length info incorrectly. Option D exposes part of the password.