Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Terraform Associate topic 1 question 38 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 38
Topic #: 1
[All Terraform Associate Questions]

You have declared a variable called var.list which is a list of objects that all have an attribute id.
Which options will produce a list of the IDs? (Choose two.)

  • A. { for o in var.list : o => o.id }
  • B. var.list[*].id
  • C. [ var.list[*].id ]
  • D. [ for o in var.list : o.id ]
Show Suggested Answer Hide Answer
Suggested Answer: AB 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
bigboi23
Highly Voted 2 years ago
Selected Answer: BD
https://www.terraform.io/language/expressions/splat A splat expression provides a more concise way to express a common operation that could otherwise be performed with a for expression.
upvoted 22 times
...
Bere
Highly Voted 9 months, 3 weeks ago
Selected Answer: BD
Here's an example: Assume you have the following variable declaration: variable "users" { default = [ { id = "id1" name = "name1" }, { id = "id2" name = "name2" }, { id = "id3" name = "name3" } ] } You can retrieve the list of IDs in your Terraform configuration using either of these options: output "users_splat" { value = var.users[*].id } output "users_for" { value = [for user in var.users : user.id] } Both these outputs will produce the same list of IDs: ["id1", "id2", "id3"].
upvoted 8 times
...
vibzr2023
Most Recent 1 month, 3 weeks ago
Apart from B and D , C is also correct > [for o in var.list : o.id] [ "1", "2", "3", ]
upvoted 2 times
...
zimomar
3 months, 3 weeks ago
Selected Answer: BD
BD for sure
upvoted 1 times
...
ndiichie
9 months, 3 weeks ago
Answer is BD. https://developer.hashicorp.com/terraform/language/expressions/splat
upvoted 2 times
...
srajvanshi
10 months ago
https://developer.hashicorp.com/terraform/language/expressions/splat B and D
upvoted 1 times
...
krishna2802
10 months, 3 weeks ago
Selected Answer: BD
https://www.terraform.io/language/expressions/splat
upvoted 1 times
...
Ni33
1 year ago
Selected Answer: AB
A and B is the correct answer
upvoted 3 times
...
AzRNoob
1 year, 1 month ago
he correct options that will produce a list of the IDs are B and D: Option B, var.list[*].id, uses the splat operator [*] to iterate over all elements of the var.list list and then accesses the id attribute of each object. The result is a list of all the id values. Option D, [ for o in var.list : o.id ], uses a list comprehension to iterate over each object in the var.list list and create a new list that contains only the id attribute of each object.
upvoted 1 times
...
camps
1 year, 1 month ago
Selected Answer: BD
B. var.list[*].id and D. [ for o in var.list : o.id ]. To produce a list of IDs from a list of objects with an id attribute, you can use either of the following options: var.list[*].id: This uses the [*] wildcard to select all elements of the var.list list, and the .id syntax to select the id attribute of each element. This will produce a list of IDs. [ for o in var.list : o.id ]: This uses a for expression to iterate over each element of var.list, selecting the id attribute of each element. This will produce a list of IDs.
upvoted 2 times
...
Power123
1 year, 1 month ago
The splat and interpolation. Ans is B & D
upvoted 1 times
...
thor7
1 year, 1 month ago
Selected Answer: BD
B and D are correct, checked them. Reference: https://developer.hashicorp.com/terraform/language/expressions/for
upvoted 1 times
...
Mal_8
1 year, 3 months ago
Selected Answer: BD
BD. Tried each expression
upvoted 1 times
...
sahara99
1 year, 3 months ago
Selected Answer: BD
A is wrong as the question asked which one creates a "list"
upvoted 2 times
...
Tanacet
1 year, 3 months ago
Selected Answer: BD
The splat and interpolation-style
upvoted 1 times
...
Mohammed52
1 year, 3 months ago
Selected Answer: BD
B and D is corrrect
upvoted 1 times
...
InformationOverload
1 year, 4 months ago
Selected Answer: BD
B and D is correct
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...