I am looking to see if it is possible to call get a value in a resource level foreach into a block within the resource. Here is the example I have. Say I have a map object of Linux VM like this:
linux = {
vm1 = {
size = "Standard_FS"
version = "8"
},
vm2 = {
size = "Standard_FS"
version = "7"
},
}
I then want to take this and use this in a resource level for each:
resource "azurerm_linux_virtual_machine" "vm" {
for_each = var.linux
name = "${each.key}.${var.domain}"
resource_group_name = var.resource_group_name
location = var.location
size = lookup(each.value, "size", "Standard_F2")
network_interface_ids = [
azurerm_network_interface.rhel_vnic[each.key].id,
]
os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_reference {
publisher = "RedHat"
offer = "RHEL"
sku = "${lookup(each.value, "version"}-LVM"
version = "latest"
}
boot_diagnostics {
storage_account_uri = var.storage_account_uri
}
}
It seems as though the source_image_reference
block is looking for its own for_each
to iterate through, and is not aware of the higher level for each at the resource level. Is there a way to get the each.value
from the resource into the sub block?