Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

Exam Terraform Associate topic 1 question 156 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 156
Topic #: 1
[All Terraform Associate Questions]

You need to write some Terraform code that adds 42 firewall rules to a security group as shown in the example.

What can you use to avoid writing 42 different nested ingress config blocks by hand?

  • A. A count loop
  • B. A for block
  • C. A for each block
  • D. A dynamic block
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Hizumi
Highly Voted 2 years, 2 months ago
Answer is D. A dynamic block acts much like a for expression, but produces nested blocks instead of a complex typed value. It iterates over a given complex value, and generates a nested block for each element of that complex value. Reference: https://www.terraform.io/language/expressions/dynamic-blocks
upvoted 9 times
...
Bere
Highly Voted 10 months, 1 week ago
Selected Answer: D
resource "aws_security_group" "many_rules" { name = "many_rules" 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 } } } variable "ingress_rules" { description = "A list of ingress rules" type = list(object({ from_port = number to_port = number protocol = string cidr_blocks = list(string) })) default = [ { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] }, # Add 41 more rules here... ] }
upvoted 6 times
...
InformationOverload
Most Recent 1 year, 11 months ago
Selected Answer: D
yep, D is correct.
upvoted 1 times
...
Rugaroo
1 year, 11 months ago
Selected Answer: D
Some additional information comparing each of the options: https://awstip.com/terraform-for-vs-for-each-7ff8506a1f94 Answer is definitely D as the question specifically mentions 'nested config(uration) blocks'
upvoted 2 times
...
noodles16668
2 years ago
Selected Answer: A
https://developer.hashicorp.com/terraform/tutorials/configuration-language/count
upvoted 1 times
...
depal_dhir
2 years, 2 months ago
Selected Answer: D
https://www.terraform.io/language/expressions/dynamic-blocks
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...