TA-002-P · Question #330
You want to define multiple data disks as nested blocks inside the resource block for a virtual machine. What Terraform feature would help you define the blocks using the values in a variable?
The correct answer is B. Dynamic blocks. Dynamic blocks allow you to generate multiple nested configuration blocks within a resource by iterating over a complex variable, which is ideal for defining multiple data disks for a virtual machine.
Question
You want to define multiple data disks as nested blocks inside the resource block for a virtual machine. What Terraform feature would help you define the blocks using the values in a variable?
Options
- ALocal values
- BDynamic blocks
- CCount arguments
- DCollection functions
How the community answered
(40 responses)- A8% (3)
- B88% (35)
- C3% (1)
- D3% (1)
Why each option
Dynamic blocks allow you to generate multiple nested configuration blocks within a resource by iterating over a complex variable, which is ideal for defining multiple data disks for a virtual machine.
Local values assign names to expressions for reuse but do not directly facilitate the dynamic creation of multiple nested blocks within a resource.
Dynamic blocks are specifically designed to generate multiple nested configuration blocks within a resource based on a complex type value, such as a list of objects from a variable, making them ideal for defining multiple data disks for a virtual machine.
The `count` argument creates multiple instances of an *entire resource block*, not multiple nested blocks within a single resource instance.
Collection functions like `for_each` or `map` help manipulate data structures, but the `dynamic` block is the specific language feature used to construct nested blocks based on those collections.
Concept tested: Terraform dynamic blocks
Source: https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks
Topics
Community Discussion
No community discussion yet for this question.