How to use nested structure in loops

I am trying to build multiple disks using Terraform and running into some trouble.

Basically I want to define vms and disks with one structure like:

vms = {
    vm1 = {
      cores          = 4
      memory     = 8
      secondary_disk = {
        disk1 = {
          disk_size = "10"
        }
        disk2 = {
          disk_size = "15"
        }
      }
    }
    vm2 = {
      cores          = 4
      memory     = 8
      secondary_disk = {
        disk1 = {
          disk_size = "10"
        }
      }
    }
  }

When I create another local map with vm_disks information like this and create disk resources:

locals {
  vm_disks = flatten([
    for vm, vm_info in var.vms : [
      for disk, disk_info in vm_info.secondary_disk : {
        vm_name = vm
        disk_name = disk
        disk_size = disk_info.disk_size
      }
    ]
  ])
}

resource "yandex_compute_disk" "vm-disk" {
  for_each = {
    for ds in local.vm_disks : "${ds.vm_name}-${ds.disk_name}" => ds
  }

  name       = "${each.value.vm_name}-${each.value.disk_name}"
  size          = each.value.disk_size
}

and now I trying to use disk resources in computer_resource
But I perhaps have reached its limit or am just not thinking it through correctly…

resource "yandex_compute_instance" "vm" {
  for_each = var.vms

  name        = each.key

  resources {
    cores         = lookup(each.value, "cores", 2)
    memory        = lookup(each.value, "memory", 2)
  }

  dynamic "secondary_disk" {
    for_each = lookup(each.value, "secondary_disk")
    content {
      disk_id = yandex_compute_disk.vm-disk.id
      auto_delete = true 
    }    
  }
}