Create multiple target groups with different IP targets

I’m trying to create multiple AWS ALB target groups with different set of IP targets for each target groups.

I have variables defined as below.

variable "target_group_names" {
  type = map(set(string))
  default = {
    "tg1" : ["10.0.0.1", "10.0.0.2"],
    "tg2" : ["10.0.1.1", "10.0.1.2", "10.0.1.3"],
    "tg3" : ["10.0.2.1", "10.0.2.2"],
    "tg4" : ["10.0.3.1", "10.0.3.2"]
  }
}

I was able to create all the target groups without any issues using below.

locals {
  target_groups = [
    for name, ips in var.target_group_names : {
      name = name
      ips  = ips
    }
  ]
}

resource "aws_lb_target_group" "target_groups" {
  for_each = {
    for idx, tg in local.target_groups : idx => tg
  }
  name        = each.value.name
  port        = 80
  protocol    = "HTTP"
  target_type = "ip"
  vpc_id      = var.aws_vpc_id

But I’m having trouble with assigning IP targets into individual target groups as specified in the map variable. (Please note number of target IPs change based on the group. some groups have 1, some have 2 IPs etc. ).

I tried few combinations and each gives me different errors. Any help would be really appreciated.

Thank you