Vnet Peering with vlans in different ressource groups

Hello Together

Im quite new to Terraform so maybe i make a very basic mistake but after multiple hours maybe here someone can help me out.

So i tried to peer to vlans together. I viewed multiple tutorials about it and the only difference between my configuration i can see is that i want to make a peering between 2 vlans that are in 2 different resource groups. I also noticed that if i put the peering in one of the 2 vlan ressource groups i have fever errors.

#Creating Resource Groups
resource "azurerm_resource_group" "network" {
  name     = "network"
  location = "West Europe"
}

resource "azurerm_resource_group" "front" {
  name     = "front"
  location = "West Europe"
}

resource "azurerm_resource_group" "middle" {
  name     = "middle"
  location = "West Europe"
}

resource "azurerm_resource_group" "back" {
  name     = "back"
  location = "West Europe"
}

resource "azurerm_resource_group" "peerings" {
  name     = "peerings"
  location = "West Europe"
}


#Creating Virtual Networks
resource "azurerm_virtual_network" "network" {
  name                = "network"
  location            = azurerm_resource_group.network.location
  resource_group_name = azurerm_resource_group.network.name
  address_space       = ["10.1.0.0/16"]
  
  subnet {
    name           = "default"
    address_prefix = "10.1.0.0/24"
  }

  subnet {
    name           = "gatewaysubnet"
    address_prefix = "10.1.1.0/24"
  }

  subnet {
    name           = "azurefirewallsubnet"
    address_prefix = "10.1.3.0/24"
  }

  subnet {
    name           = "azurebastionsubnet"
    address_prefix = "10.1.2.0/24"
  }
}

resource "azurerm_virtual_network" "front" {
  name                = "network"
  location            = azurerm_resource_group.front.location
  resource_group_name = azurerm_resource_group.front.name
  address_space       = ["10.2.0.0/16"]
}

resource "azurerm_virtual_network" "middle" {
  name                = "network"
  location            = azurerm_resource_group.middle.location
  resource_group_name = azurerm_resource_group.middle.name
  address_space       = ["10.3.0.0/16"]
}

resource "azurerm_virtual_network" "back" {
  name                = "network"
  location            = azurerm_resource_group.back.location
  resource_group_name = azurerm_resource_group.back.name
  address_space       = ["10.4.0.0/16"]
}

#Create peerings
#network <--> front
resource "azurerm_virtual_network_peering" "networktofront" {
  name                      = "networktofront"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.network.name
  remote_virtual_network_id = azurerm_virtual_network.front.id
}

resource "azurerm_virtual_network_peering" "fronttonetwork" {
  name                      = "fronttonetwork"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.front.name
  remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> middle
resource "azurerm_virtual_network_peering" "networktomiddle" {
  name                      = "networktomiddle"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.network.name
  remote_virtual_network_id = azurerm_virtual_network.middle.id
}

resource "azurerm_virtual_network_peering" "middletonetwork" {
  name                      = "middletonetwork"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.middle.name
  remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> back
resource "azurerm_virtual_network_peering" "networktoback" {
  name                      = "networktoback"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.network.name
  remote_virtual_network_id = azurerm_virtual_network.back.id
}

resource "azurerm_virtual_network_peering" "backtonetwork" {
  name                      = "backtonetwork"
  resource_group_name       = azurerm_resource_group.peerings.name
  virtual_network_name      = azurerm_virtual_network.back.name
  remote_virtual_network_id = azurerm_virtual_network.network.id
}

solution: azure - Terraform Vnet Peering with vlans in different ressource groups - Stack Overflow