Recall & Review
beginner
What is a dynamic block in Terraform?
A dynamic block lets you generate multiple nested blocks inside a resource or module based on a list or map. It helps when the number of nested blocks is not fixed and depends on input data.
Click to reveal answer
beginner
What does
for_each do in Terraform?for_each lets you create multiple instances of a resource or module, one for each item in a map or set. It is used to manage multiple similar resources efficiently.Click to reveal answer
intermediate
When should you use a dynamic block instead of for_each?
Use a dynamic block when you need to create multiple nested blocks inside a single resource or module instance, especially when the nested blocks vary in number or content.
Click to reveal answer
intermediate
When is for_each preferred over dynamic blocks?
Use for_each when you want to create multiple separate resource or module instances, each representing a distinct item, rather than multiple nested blocks inside one resource.
Click to reveal answer
advanced
Can you combine dynamic blocks and for_each in Terraform?
Yes, you can use for_each to create multiple resource instances and inside each resource use dynamic blocks to generate nested blocks based on data. This allows flexible and scalable configurations.
Click to reveal answer
What does a dynamic block in Terraform generate?
✗ Incorrect
Dynamic blocks generate multiple nested blocks inside one resource based on input data.
Which Terraform feature creates multiple resource instances from a map or set?
✗ Incorrect
for_each creates multiple resource or module instances, one per item.When should you use for_each instead of dynamic blocks?
✗ Incorrect
Use for_each to create multiple separate resource instances.
Can dynamic blocks be used inside resources created with for_each?
✗ Incorrect
Dynamic blocks can be used inside each resource instance created by for_each.
What is a key benefit of using dynamic blocks?
✗ Incorrect
Dynamic blocks simplify creating multiple nested blocks based on variable data.
Explain the difference between dynamic blocks and for_each in Terraform and when to use each.
Think about whether you want many blocks inside one resource or many separate resources.
You got /4 concepts.
Describe a scenario where combining for_each and dynamic blocks is useful in Terraform.
Imagine managing many servers each with multiple network interfaces.
You got /4 concepts.