Hi,
I stuck creating dynamics conditions in the aws_lb_listener_rule resource.
I need to assign header_host, path_pattern, etc tag dynamically inside the conditions block, but i dont found how to do in the doc (Dynamic Blocks - Configuration Language - Terraform by HashiCorp)
any ideas?
Many Thanks!!
locals {
conditions = [{
field = "host_header",
values = ["example.com"],
},
{
field = "path_pattern",
values = ["/static/*"],
}]
}
resource "aws_lb_listener_rule" "path_pattern" {
listener_arn = aws_lb_listener.test.arn
priority = 100
action {
type = "forward"
target_group_arn = aws_lb_target_group.test.arn
}
dynamic "condition" {
for_each = local.conditions
content {
host_header { # <--- how to assign this tag dynamically (conditions.value.field)??
values = condition.value.values
}
}
}
}
Thanks @Karthic, but what is the syntax to do it within a dynamic block?
I tried several ways without luck, and in the doc there are not examples to achieve this.
For example, in previous version of plugin the block to conditions was:
# previuos plugin (don´t remenber which)
condition {
field = "host-header"
values = ["dev01site.example.com"]
}
# with dynamic
dynamic "condition" {
for_each = local.conditions
content {
field = condition.value.field # <-- same way all rest of paramaters in block content
values = condition.value.values
}
}
But with current syntaxis not found way to do it
# actual plugin (3.24)
condition {
host_header { # <-- I need assign this tag dinamically, how?
values = ["example.com"]
}
}
# with dynamic
¿?
I was testing different ALB rules parameters with the new syntax this way, assuming we only keep receiving “host-header” and “path-pattern” fields from previous version modules:
condition {
dynamic "host_header" {
for_each = { for i in var.service_alb_rules : i.field => i if i.field == "host-header" }
content {
values = [host_header.value.value]
}
}
dynamic "path_pattern" {
for_each = { for i in var.service_alb_rules : i.field => i if i.field == "path-pattern" }
content {
values = [path_pattern.value.value]
}
}
}