Which construct can be used to avoid writing 42 nested ingress blocks by hand?

Prepare for the HashiCorp Terraform Associate Exam. Utilize flashcards and multiple-choice questions with detailed hints and explanations. Boost your confidence and be ready for success!

Multiple Choice

Which construct can be used to avoid writing 42 nested ingress blocks by hand?

Explanation:
When you need to generate many similar nested blocks inside a single resource, dynamic blocks provide the right solution. A dynamic block lets you loop over a collection and render one nested block per item, so you don’t have to hand-write dozens of blocks. For example, with a security group you can keep a list of ingress rules and use a dynamic block to create an ingress block for each rule automatically. The content inside the dynamic block uses each.value to fill in the details like from_port, to_port, protocol, and cidr_blocks. The other constructs don’t fit this use case. Count applies to entire resources, not to arbitrary nested blocks; there isn’t a standalone “for block” or “for each block” construct to repeat inner blocks. Dynamic blocks explicitly handle repeating nested blocks, which is why they’re the best choice here.

When you need to generate many similar nested blocks inside a single resource, dynamic blocks provide the right solution. A dynamic block lets you loop over a collection and render one nested block per item, so you don’t have to hand-write dozens of blocks. For example, with a security group you can keep a list of ingress rules and use a dynamic block to create an ingress block for each rule automatically. The content inside the dynamic block uses each.value to fill in the details like from_port, to_port, protocol, and cidr_blocks.

The other constructs don’t fit this use case. Count applies to entire resources, not to arbitrary nested blocks; there isn’t a standalone “for block” or “for each block” construct to repeat inner blocks. Dynamic blocks explicitly handle repeating nested blocks, which is why they’re the best choice here.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy