0
0
Terraformcloud~20 mins

Why dynamic blocks reduce repetition in Terraform - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic Blocks Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding dynamic blocks in Terraform

Which statement best explains why dynamic blocks in Terraform reduce repetition?

AThey allow you to write a single block that can generate multiple nested blocks based on a list or map, avoiding manual copy-pasting.
BThey replace all variables with fixed values, so you only write blocks once.
CThey automatically create resources without any configuration, so you don't need to write blocks at all.
DThey remove the need for any loops or conditions in Terraform configurations.
Attempts:
2 left
💡 Hint

Think about how you can generate repeated blocks from data structures instead of copying code.

Configuration
intermediate
2:00remaining
Output count of nested blocks generated by dynamic block

Given this Terraform snippet using a dynamic block, how many ingress blocks will be created?

resource "aws_security_group" "example" {
  name = "example"

  dynamic "ingress" {
    for_each = var.rules
    content {
      from_port   = ingress.value.from_port
      to_port     = ingress.value.to_port
      protocol    = ingress.value.protocol
      cidr_blocks = ingress.value.cidr_blocks
    }
  }
}

Assuming var.rules is a list with 3 elements.

A3
B1
C0
DDepends on the number of security groups
Attempts:
2 left
💡 Hint

Dynamic blocks create one nested block per item in the collection.

Architecture
advanced
2:30remaining
Choosing dynamic blocks for modular Terraform design

You are designing a Terraform module to create firewall rules. You want to support any number of rules without repeating code. Which approach best uses dynamic blocks to achieve this?

AUse count on the resource itself to create multiple resources, each with a single rule block hardcoded.
BManually write one block per rule and require users to copy the module multiple times.
CUse a dynamic block with for_each over a variable list of rules to generate nested rule blocks inside the resource.
DUse a static block with a fixed number of rules and ignore extra rules.
Attempts:
2 left
💡 Hint

Think about how to generate multiple nested blocks inside one resource dynamically.

service_behavior
advanced
2:00remaining
Effect of dynamic blocks on resource behavior

When using dynamic blocks to create multiple nested blocks in a Terraform resource, what is the effect on the deployed infrastructure?

AOnly the first nested block generated by the dynamic block will be applied to the infrastructure.
BThe infrastructure will have multiple nested configurations applied as specified by the dynamic block iterations.
CDynamic blocks only affect Terraform state but do not change the actual infrastructure.
DThe resource will fail to deploy because dynamic blocks are not supported by providers.
Attempts:
2 left
💡 Hint

Consider how Terraform translates configuration into real infrastructure changes.

security
expert
3:00remaining
Security risks of improper dynamic block usage

What is a potential security risk when using dynamic blocks in Terraform to generate firewall rules from user input without validation?

ADynamic blocks prevent any changes to firewall rules once applied.
BDynamic blocks automatically encrypt all inputs, so no security risk exists.
CTerraform will reject any dynamic block with user input, preventing risks.
DUnvalidated input could create overly permissive firewall rules, exposing resources to unwanted access.
Attempts:
2 left
💡 Hint

Think about what happens if user data controls security settings without checks.