Conditionals with for_each

Not sure I have the right approach here, but I am trying to craft a conditional statement to a for_each statement to create a set of resources

For example, setting up an ALB I have two variables

create_alb = true
create_https_listener = true

Along with a variable named rule_set defining a map of rule resources

If both of these vars are true, apply a set of aws_lb_listener_rule resources defined in a the var.rule_set map to the https_listener.

If create_https_listener = false, apply the same set of rules to a http_listener

If create_alb = false, don’t create any of these resources

I can do a conditional for something like

count = var.create_alb == true ? length(var.rule_set) : 0

But I’m struggling using my map on the multiple inline blocks for the rules (eg action{} & condition {} for forward rules)

Ideally I would not use count, but use for_each to define the number of rules to create

Something like

for_each =

I see examples of using something like

for_each = {for key, value in var.rule_set:
key => lower(value)
if var.create_alb == true
}

Is there a way to just use the for_each with an if statement? As my map has different data types in it, I can’t use a simple function to do something innocuous

for_each = {var.rule_set: if var.create_alb == true}

I feel like there is something simple I’m just not grasping