Terraform For Expressions and if conditions

Terraform How to use conditional if in for with map object that I would like to add to a target group based on the environment and EC2 instance function.
I have an environment variable with 3 default values dev, test, and prod and Target group map consisting of the servers as keys, port, target_group, target_group_arn, and a condition.
Here is the output that I’m trying to achieve.
If the environment is dev or test, I would like the output to be the following.
Port: 22

target_group : “server-1-target”

tar_group_arn : “arn-temple-number-1”


Port: 8567

target_group : “server-3-target”

tar_group_arn : “arn-temple-number-3”


Port: 9300

target_group : “server-4-target”

tar_group_arn : “arn-temple-number-4”


If the environment is prod I would like the output to be the following.

Port: 22

target_group : “server-1-target”

tar_group_arn : “arn-temple-number-1”


Port: 8567

target_group : “server-3-target”

tar_group_arn : “arn-temple-number-3”


Thanks for any advice that you can provide.
Here’s the code.

variable “enviroment” {
type = string
description = “Please enter working enviroment: dev,test,prod”
}

variable “target_group” {
description = “Map of target_group configuration.”
type = map(object({
target_group = string
target_group_arn = string
port = number
condition = bool
}))
default = {
server_1= {
port : 22
target_group : “server-1-target”
tar_group_arn : “arn-temple-number-1”
condition : true
},
server_2 = {
port : 22
target_group : “server-2-target”
tar_group_arn : “arn-temple-number-2”
condition : false
},
server_3 = {:
port : 8567
target_group : “server-3-target”
tar_group_arn : “arn-temple-number-3”
condition : true
},
server_4 = {
port : 9300
target_group : “server-4-target”
tar_group_arn : “arn-temple-number-4”
condition : true
}
}
}

locals {
target_output_map = tomap({
for instance in var.target_group :
instance.target_group => instance.target_group
})
}

locals {
map_of_needed_values = tomap({
for instances in var.target_group :
instance.target_group => instance.target_group if ((var.enviroment == “prod”) && (instance.target_group != “server-3-target”)) || instance.condition
}
}

output “target_output_map” { value =local.map_of_needed_values )
output “map_of_needed_values” { value = local.map_of_needed_values }