Complete the code to define a dynamic block for security group rules.
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.[1] } }
The cidr_blocks attribute specifies the IP ranges for the ingress rule. It must match the variable's key.
Complete the code to iterate over a list of tags using dynamic blocks.
resource "aws_instance" "example" { ami = var.ami instance_type = var.instance_type dynamic "tag" { for_each = [1] content { key = tag.key value = tag.value } } }
The dynamic block iterates over var.tags to create tags for the instance.
Fix the error in the dynamic block to correctly reference the iterator variable.
dynamic "egress" { for_each = var.egress_rules content { from_port = [1].from_port to_port = egress.value.to_port protocol = egress.value.protocol cidr_blocks = egress.value.cidr_blocks } }
The iterator variable is egress, and its value must be accessed with egress.value.
Fill both blanks to create a dynamic block for multiple ingress rules with correct iteration and attribute access.
dynamic "ingress" { for_each = [1] content { from_port = ingress.[2].from_port to_port = ingress.value.to_port protocol = ingress.value.protocol cidr_blocks = ingress.value.cidr_blocks } }
The dynamic block iterates over var.ingress_rules, and the current item is accessed with ingress.value.
Fill all three blanks to define a dynamic block for tags with correct iteration, key, and value references.
dynamic "tag" { for_each = [1] content { key = tag.[2] value = tag.[3] } }
The dynamic block iterates over var.tags, and inside the block, tag.key and tag.value access the tag's key and value.