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, making configuration flexible and reusable.
Click to reveal answer
beginner
Which keyword starts a dynamic block in Terraform?
The keyword
dynamic starts a dynamic block, followed by the block type in quotes, like dynamic "ingress".Click to reveal answer
intermediate
What are the two main parts inside a dynamic block?
Inside a dynamic block, you have
for_each to loop over a collection, and content which defines the block structure to repeat.Click to reveal answer
intermediate
Why use dynamic blocks instead of static blocks?
Dynamic blocks reduce repetition by generating multiple blocks from data, making configurations easier to maintain and adapt to changing inputs.
Click to reveal answer
advanced
Show a simple example of a dynamic block creating multiple
ingress rules.Example:<br>
dynamic "ingress" {
for_each = var.ingress_rules
content {
from_port = ingress.value.from_port
to_port = ingress.value.to_port
protocol = ingress.value.protocol
cidr_blocks = ingress.value.cidr_blocks
}
}Click to reveal answer
What does the
for_each attribute inside a dynamic block do?✗ Incorrect
for_each loops over a list or map to generate multiple nested blocks dynamically.
Which part of a dynamic block defines the repeated block's structure?
✗ Incorrect
The content block defines the structure of each repeated nested block.
True or False: Dynamic blocks can only be used inside resource blocks.
✗ Incorrect
Dynamic blocks can be used inside resources, modules, and other block types that support nested blocks.
What happens if the
for_each collection is empty in a dynamic block?✗ Incorrect
If for_each is empty, no nested blocks are generated inside the dynamic block.
Which of these is a benefit of using dynamic blocks?
✗ Incorrect
Dynamic blocks help avoid manual repetition by generating blocks from data collections.
Explain how a dynamic block works in Terraform and when you would use it.
Think about how to create multiple similar blocks from a list or map.
You got /4 concepts.
Describe the structure of a dynamic block with an example of creating multiple ingress rules.
Imagine you want to add many firewall rules without writing each one manually.
You got /4 concepts.