Terraform use count.index or key reference in nested dynamic block

I have the following code for a ‘google_compute_url_map’

  dynamic "path_matcher" {
  for_each = var.url_map_path_matcher
  content {
    name = path_matcher.key
    default_service = lookup(path_matcher.key, "default_service", null)
    dynamic "path_rule" {
      for_each = lookup(var.url_map_path_rules, path_matcher.key, null)
      content {
        paths = lookup(path_rule.value, "paths", null)
        service = lookup(path_rule.value, "service", null)
        }
      }
    }
  }

Due to the complexity of the variables I split the URL map and the path rules in two variables. How can I reference the index position of the first dynamic block variable in the for_each loop to be used across the two variables to make sure that the correct paths apply? Like in below example…

Any help or pointer in the right direction is greatly appreciated, been breaking my head over this the entire weekend.

  variable "url_map_path_matcher" {
    type = map(object({
      default_service = string
    }))
    description = "Variables to set the URL Map Path matcher"
  }

  variable "url_map_path_rules" {
    type = map(map(object({
      paths           = list(string)
      service         = string
    })))
    description = "Variables to set the URL Map Path rules"
  }

Example content:

    "url_map_path_matcher": {
        "allpaths": {
            "default_service": "echo"
        },
        "service1": {
            "default_service": "service1"
        },
    },
    "url_map_path_rules": {
      "allpaths": { 
        "path_rule_1": {
            "paths": [
                "/echo",
                "/echo/*"
            ],
            "service": "echo"
        },
        "path_rule_2": {
            "paths": [
                "/ping"
            ],
            "service": "ping"
        },
        "path_rule_3": {
            "paths": [
                "/my-new-svc"
            ],
            "service": "my-new-svc"
        },
      },
      "service1": {
        "path_rule_1": {
            "paths": [
                "/pingservice"
            ],
            "service": "pingservice"
        },
        "path_rule_2": {
            "paths": [
                "/service1"
            ],
            "service": "service1"
        },
      }
    }

The error I’m getting when running terraform plan is :

│ Error: Invalid function argument
│ 
│   on lb-http.tf line 52, in resource "google_compute_url_map" "lb01_url_map":
│   52:     default_service = lookup(path_matcher.key, "default_service", null)
│     ├────────────────
│     │ path_matcher.key is "allpaths"
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.
╵
╷
│ Error: Invalid function argument
│ 
│   on lb-http.tf line 52, in resource "google_compute_url_map" "lb01_url_map":
│   52:     default_service = lookup(path_matcher.key, "default_service", null)
│     ├────────────────
│     │ path_matcher.key is "service1"
│ 
│ Invalid value for "inputMap" parameter: lookup() requires a map as the
│ first argument.

Kind regards,

Eric V.