Terraform-Associate-004 practice question 15 of 35
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?
Full set: 360 questionsDynamic blocks are a specific Terraform feature designed to create multiple nested configuration blocks within a single resource definition. They iterate over a complex variable, such as a list of maps, and generate a block for each item in the collection. This directly addresses the requirement of defining multiple data disks (which are nested blocks) for a virtual machine based on the values in a variable. This approach avoids repetitive code and allows the configuration to be flexible and data-driven.
A. Local values: Local values are used to assign a name to an expression, creating a reusable variable within a module. They do not generate configuration blocks.
B. Count arguments: The count meta-argument creates multiple independent instances of a resource, not multiple nested blocks within a single resource.
C. Collection functions: Collection functions (e.g., merge, flatten) are used to manipulate and transform data structures like lists and maps, but they do not create configuration blocks themselves.
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... A dynamic block acts like a for expression, but produces nested blocks instead of a complex typed value." This page provides a direct explanation and examples of using dynamic blocks for the exact purpose described in the question.
2. HashiCorp Terraform Documentation, "The count Meta-Argument": "The count meta-argument... creates several instances of a resource or module." This clarifies that count operates at the resource level, not on nested blocks within a resource.
3. HashiCorp Terraform Documentation, "Local Values": "A local value assigns a name to an expression, allowing it to be used multiple times within a module without repeating it." This defines the purpose of locals as reusable expressions, not block generators.
Keep practicing
Take the free Terraform-Associate-004 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Terraform-Associate-004 practice questions
- Question 1You should run terraform fnt to rewrite all Terraform configurations within the current w…
- Question 2Module variable assignments are inherited from the parent module and you do not need to e…
- Question 3terraform validate confirms thesyntaxof Terraform files.
- Question 4Using the terraform state rm command against a resource will destroy it.
- Question 5Variables declared within a module are accessible outside of the module.
- Question 6terraform init retrieves and caches the configuration for all remote modules.
