0
0
Terraformcloud~10 mins

For expressions for transformation in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a list of doubled numbers using a for expression.

Terraform
output "doubled" {
  value = [for num in var.numbers : num [1] 2]
}
Drag options to blanks, or click blank then click option'
A/
B*
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * will add 2 instead of doubling.
Using / or - will not double the numbers.
2fill in blank
medium

Complete the code to create a map of instance names to their IDs using a for expression.

Terraform
output "instance_map" {
  value = {for inst in var.instances : inst.name => inst.[1]
}
Drag options to blanks, or click blank then click option'
Aname
Btype
Cid
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using inst.name as value duplicates the key.
Using inst.type or inst.count are not valid for IDs.
3fill in blank
hard

Fix the error in the for expression to filter only even numbers.

Terraform
output "even_numbers" {
  value = [for n in var.numbers : n if n [1] 2 == 0]
}
Drag options to blanks, or click blank then click option'
A+
B*
C/
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or * will not filter even numbers.
Using / returns a quotient, not remainder.
4fill in blank
hard

Fill both blanks to create a map of server names to their IP addresses, filtering only active servers.

Terraform
output "active_servers" {
  value = {for s in var.servers : s.[1] => s.[2] if s.active}
}
Drag options to blanks, or click blank then click option'
Aname
Bip
Cid
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or status instead of name or ip.
Not filtering by active status.
5fill in blank
hard

Fill all three blanks to create a map of uppercase user names to their emails, filtering users with verified emails.

Terraform
output "verified_user_emails" {
  value = {for user in var.users : user.[1].[2]() => user.[3] if user.email_verified}
}
Drag options to blanks, or click blank then click option'
Aname
Bupper
Cemail
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower() instead of upper() for names.
Using email_verified as key instead of filtering condition.