Boilerplate code is pain for anyone who try to refactor existing architecture, terraform provides dynamic block to remove repetitive code blocks.
dynamic "ingress" {
for_each = ["80", "8080", "443", "1000", "8443"]
content {
description = "Allow port HTTP"
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
dynamic "ingress" {
for_each = ["8000", "9000", "7000", "1000"]
content {
description = "Allow port UDP"
from_port = ingress.value
to_port = ingress.value
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
}