Obtain vnet Id from a data source which is a for_each object

eastus_rg  = somerg
westeu_rg = somerg1
Input = {
  Prod = [
    {
      cidr = ["172.0.0/24"]
      vnet_name = "vnet1"
      rg   = "prodrg1"
      location = "eastus"
    },
    {
      cidr = ["172.1.0.0/24"]
      vnet_name = "vnet2"
      rg   = "prodrg2"
      location = "eastus"
    }
  ],
  nonProd = [
     {
      cidr = ["10.0.0/24"]
      vnet_name = "NPvnet1"
      rg   = "nonprodrg1"
      location = "eastus"
    },
    {
      cidr = ["10.10.1.0/24"]
      vnet_name = "NPvnet2"
      rg   = "nonprodrg2"
      location = "eastus"
    }
  ]
}





locals {
  flat_vnet_rg_permissions = merge([
      for env_name, env_vn_list in var.Input :
         {
           for idx, env_vn in env_vn_list:
             "${env_name}-${idx}" => env_vn
         }
    ]...)
}


data "azurerm_virtual_network" "westvnets" {
  for_each =   { for k, v in local.flat_vnet_rg_permissions : k => v  if v.location == "westeu" }
  name                = each.value["vnet_name"]
  resource_group_name = each.value.rg
}

resource "azurerm_virtual_network_peering" "peerwesthub" {
  for_each                  = data.azurerm_virtual_network.westvnets
  name                      = "vnet-peer-west"-${each.key}
  remote_virtual_network_id = each.value.outputs.id
  resource_group_name       = each.value.rg
  virtual_network_name      = each.value.name
}

How would I proprly fetch the remote_virtual_network_id from each iteration of the above data source and also set a meaningful peer name that would help to identify ?

Looking over the code you have posted I think you want to do this:

locals {
   westvnets = { for k, v in local.flat_vnet_rg_permissions : k => v  if v.location == "westeu" } 
}

I made this a local so I could reuse it. I also fixed the location error

data "azurerm_virtual_network" "westvnets" {
  for_each            =  local.westvnets
  name                = each.value.vnet_name
  resource_group_name = each.value.rg
}

resource "azurerm_virtual_network_peering" "peerwesthub" {
  for_each                  =  local.westvnets
  name                      = "vnet-peer-west-${each.key}"
  remote_virtual_network_id = data.azurerm_virtual_network[each.key].id
  resource_group_name       = each.value.rg   
  virtual_network_name      = each.value.vnet_name
}

OR I think you could do this:

resource "azurerm_virtual_network_peering" "peerwesthub" {
  for_each                  = data.azurerm_virtual_network.westvnets 
  name                      = "vnet-peer-west-${each.key}"
  remote_virtual_network_id = each.value.id
  resource_group_name       = each.value.resource_group_name   
  virtual_network_name      = each.value.virtual_network_name
}