TERRAFORM-ASSOCIATE-003 practice question 30 of 30

[Manage Terraform Resources and Providers] What type of block is used to construct a collection of nested configuration blocks?

Full set: 226 questions
Answer options
A: Dynamic Correct answer
B: For_each
C: Nesting
D: repeated.
Correct Answer:
A. Dynamic
Explanation

The dynamic block is a specific construct in Terraform's configuration language (HCL) used to dynamically generate multiple nested configuration blocks within a resource. It iterates over a given complex data type, such as a list or a map, and generates a nested block for each item in the collection. This is particularly useful for resource arguments that expect a series of similar configuration blocks, like defining multiple ingress rules for a security group or multiple disk attachments for a virtual machine, without having to write a separate static block for each one.

Why Incorrect

B. Foreach: The foreach meta-argument is used to create multiple instances of an entire resource, module, or data source, not for creating nested blocks within a single resource.
C. Nesting: "Nesting" is a general term describing the structure of placing blocks within other blocks in HCL, but it is not a specific keyword or block type for dynamic generation.
D. repeated: "repeated" is not a keyword or a block type in the Terraform language for constructing collections of nested blocks.

References

1. HashiCorp Terraform Documentation, "Dynamic Blocks": "You can dynamically construct repeatable nested blocks, such as setting for an azurermappservice resource, using a special dynamic block type, which is supported inside resource, data, provider, and provisioner blocks."

2. HashiCorp Terraform Documentation, "The foreach Meta-Argument": "The foreach meta-argument creates multiple instances of a resource or module... It is not intended for creating multiple nested blocks within a resource."

3. HashiCorp Terraform Documentation, "Configuration Syntax - Blocks": This section details the general structure of configuration blocks but does not list "Nesting" or "repeated" as special block types for dynamic construction. The dynamic block is the specific feature for this purpose.

Scroll to Top