What type of block is used to construct a collection of nested configuration blocks?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

What type of block is used to construct a collection of nested configuration blocks?

Explanation:
Dynamic blocks let you build a collection of nested blocks by iterating over a list or map and generating multiple blocks of the same type inside a resource or module. This approach is what lets Terraform create several similar configurations without writing them out one by one. Inside a dynamic block you use for_each to decide how many nested blocks to generate, and content to define the fields for each generated block, typically referencing each.value for the current item. For example, you can add multiple ingress rules to a security group by a dynamic block that iterates over a list of rule objects and fills in from_port, to_port, protocol, and cidr_blocks for each. The other terms aren’t block types Terraform uses to achieve this repetition—for_each is the looping construct used with a dynamic block, while nesting and repeated aren’t Terraform block constructs.

Dynamic blocks let you build a collection of nested blocks by iterating over a list or map and generating multiple blocks of the same type inside a resource or module. This approach is what lets Terraform create several similar configurations without writing them out one by one. Inside a dynamic block you use for_each to decide how many nested blocks to generate, and content to define the fields for each generated block, typically referencing each.value for the current item. For example, you can add multiple ingress rules to a security group by a dynamic block that iterates over a list of rule objects and fills in from_port, to_port, protocol, and cidr_blocks for each. The other terms aren’t block types Terraform uses to achieve this repetition—for_each is the looping construct used with a dynamic block, while nesting and repeated aren’t Terraform block constructs.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy