nerdexam
HashiCorp

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.

Read, generate, and modify configuration

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)
  • A
    8% (3)
  • B
    88% (35)
  • C
    3% (1)
  • D
    3% (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.

ALocal values

Local values assign names to expressions for reuse but do not directly facilitate the dynamic creation of multiple nested blocks within a resource.

BDynamic blocksCorrect

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.

CCount arguments

The `count` argument creates multiple instances of an *entire resource block*, not multiple nested blocks within a single resource instance.

DCollection functions

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

#Dynamic blocks#Nested blocks#Variables#Configuration language

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice