User Tools

Site Tools


burim:terraform:maps
Sure, let's break down the expression { for k, v in data.azurerm_virtual_network.this-vnet : k => v.id } in simple terms:
for k, v in data.azurerm_virtual_network.this-vnet:
This part is a loop that iterates over each item in the data.azurerm_virtual_network.this-vnet map.
k represents the key (e.g., "westeurope" or "brazilsouth").
v represents the value, which is the data object for the virtual network.
k => v.id:
This part creates a new map where each key (k) is the same as the key from the original map.
The value for each key in the new map is v.id, which is the ID of the virtual network.
{ ... }:
The curly braces { ... } denote that we are creating a new map.
In summary, this expression creates a new map where:
The keys are the same as the keys from the original data.azurerm_virtual_network.this-vnet map.
The values are the IDs of the virtual networks.
For example, if data.azurerm_virtual_network.this-vnet contains:
{
"westeurope": { "id": "vnet-id-1" },
"brazilsouth": { "id": "vnet-id-2" }
}
  • The resulting map will be:
{
"westeurope": "vnet-id-1",
"brazilsouth": "vnet-id-2"
}
This allows you to easily access the IDs of the virtual networks by their region names.
burim/terraform/maps.txt · Last modified: 2024/09/20 11:37 by burim

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki