0
0
Terraformcloud~10 mins

Why dynamic blocks reduce repetition in Terraform - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a dynamic block in Terraform.

Terraform
dynamic "[1]" {
  for_each = var.items
  content {
    cidr_blocks = [each.value]
  }
}
Drag options to blanks, or click blank then click option'
Aresource
Bitem
Cblock
Dingress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'resource' instead of the block name.
Using 'block' which is not a valid block name.
Using 'item' which is a variable name, not a block.
2fill in blank
medium

Complete the code to access each item in the dynamic block.

Terraform
content {
  cidr_blocks = [each.value.[1]]
}
Drag options to blanks, or click blank then click option'
Acidr_block
Bcidr
Ccidr_blocks
Dcidrblock
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cidr' which is incomplete.
Using 'cidr_blocks' which is the list, not the property.
Using 'cidrblock' which is misspelled.
3fill in blank
hard

Fix the error in the dynamic block to correctly iterate over a list.

Terraform
dynamic "ingress" {
  for_each = [1]
  content {
    from_port   = each.value.from_port
    to_port     = each.value.to_port
    protocol    = each.value.protocol
  }
}
Drag options to blanks, or click blank then click option'
Avar.ingress_rules
Bvar.ingress_rule
Cvar.ingress
Dvar.rules
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'ingress_rule' which is not a list.
Using a generic 'rules' which may not exist.
Using 'ingress' which may be a block name, not a variable.
4fill in blank
hard

Fill both blanks to add the Name tag to the resource.

Terraform
resource "aws_instance" "example" {
  ami           = var.ami
  instance_type = var.instance_type

  tags = {
    [1] = [2]
  }
}
Drag options to blanks, or click blank then click option'
AName
Bvar.name
CEnvironment
Dvar.environment
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names as keys instead of strings.
Mixing up keys and values.
Using incorrect variable names.
5fill in blank
hard

Fill all three blanks to define a dynamic block for multiple security group egress rules.

Terraform
dynamic "egress" {
  for_each = [1]
  content {
    from_port   = each.value.[2]
    to_port     = each.value.[3]
    protocol    = each.value.protocol
  }
}
Drag options to blanks, or click blank then click option'
Avar.egress_rules
Bfrom_port
Cto_port
Dvar.rules
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable that is not a list.
Swapping 'from_port' and 'to_port' names.
Using generic variable names like 'rules' without context.