I have the code below in which I create vnets in for\_each block:

```
provider "azurerm" {
  features {}
}

variable "vnets" {
  type = map(object({
    name          = string
    address_space = list(string)
  }))
  default = {
    "vnet1" = {
      "name"          = "vnet1",
      "address_space" = ["10.0.0.0/16"]
    },
    "vnet2" = {
      "name"          = "vnet2",
      "address_space" = ["10.1.0.0/16"]
    }
  }
}

resource "azurerm_resource_group" "vnets" {
  name     = "vnets"
  location = "WestEurope"
}

resource "azurerm_virtual_network" "virtual_network" {
  for_each = var.vnets
    name                =       each.value.name
    location            =       "West Europe"
    resource_group_name =       azurerm_resource_group.vnets.name
    address_space       =       each.value.address_space
}

```

Everything works with the plan, virtual networks will be created,
but the problem is how to get to the created resources from the for\_each block?

When I type the command to return the resources list:

```
terraform state list

```

Then I have the following output from console:

```
azurerm_resource_group.vnets
azurerm_virtual_network.virtual_network["vnet1"]
azurerm_virtual_network.virtual_network["vnet2"]

```

And when I want to use a vnet1 anywhere in the code using reference azurerm\_virtual\_network.virtual\_network["vnet1"] then I'm getting an error.

For example, I want to view resource vnet1:

```
terraform state show azurerm_virtual_network.virtual_network["vnet1"]

```

Im getting such error:

```
Error parsing instance address: azurerm_virtual_network.virtual_network[vnet1]

This command requires that the address references one specific instance.
To view the available instances, use "terraform state list". Please modify
the address to reference a specific instance.

```

I tried the following commands to access a resource, but they don't work:

```
terraform state show azurerm_virtual_network.virtual_network["vnet1"]
terraform state show 'azurerm_virtual_network.virtual_network["vnet1"]'
terraform state show azurerm_virtual_network.virtual_network[vnet1]
terraform state show azurerm_virtual_network.virtual_network[0]
terraform state show azurerm_virtual_network.virtual_network.vnet1

```

Do you know how to solve it?