I am trying to figure out how to create a list based on conditions within a dynamic block. My specific use case is using the aws_proxy_protocol_policy
for an ELB only when the listener is using TCP. I have the following dynamic listener block
dynamic "listener" {
for_each = [for i in "${var.dynamic_listener}" : {
instance_port = i.instance_port
instance_protocol = i.instance_protocol
lb_port = i.lb_port
lb_protocol = i.lb_protocol
ssl_certificate_id = i.ssl_certificate_id
}]
content {
instance_port = listener.value.instance_port
instance_protocol = listener.value.instance_protocol
lb_port = listener.value.lb_port
lb_protocol = listener.value.lb_protocol
ssl_certificate_id = listener.value.ssl_certificate_id
}
}
and would like to build a list of instance_ports based on ONLY listeners with instance_protocols of ‘TCP’
resource "aws_proxy_protocol_policy" "proxy_protocol" {
count = "${(lower(var.proxy_protocol_enabled) == "true") ? 1 : 0 }"
load_balancer = "${aws_elb.elb}"
instance_ports = ?????
}
I tried something like
instance_ports = [for i in "${var.dynamic_listener}" : {
instance_ports = flatten([i.instance_protocol == "TCP" ? i.instance_port : null])}]
But am not having much success. Any thoughts?