Hi All,
I am facing an issue while creating and attaching the managed disk in terraform. At the plan creation time, i could see the lun id are assigned sequentially, but at the creation time its assigning randomly.
resource "azurerm_managed_disk" "linux_vm_disk" {
for_each = local.all_linux_vm_disk
name = each.key
location = azurerm_linux_virtual_machine.linux_vm[each.value.vm_name].location
resource_group_name = azurerm_linux_virtual_machine.linux_vm[each.value.vm_name].resource_group_name
storage_account_type = each.value.Type
create_option = lookup(each.value,"create_option","Empty")
disk_size_gb = each.value.Size
tags = merge(local.lz.Tags[0],{
Resourcetype="Managed Disk"
})
}
resource "azurerm_virtual_machine_data_disk_attachment" "linux_vm_disk_attachment" {
for_each = local.all_linux_vm_disk
managed_disk_id = azurerm_managed_disk.linux_vm_disk[each.key].id
virtual_machine_id = azurerm_linux_virtual_machine.linux_vm[each.value.vm_name].id
#The Logical Unit Number of the Data Disk, which needs to be unique within the Virtual Machine.
#Changing this forces a new resource to be created
lun = lookup(each.value, "lun", "1")
caching = lookup(each.value,"Cache","None")
lifecycle {
ignore_changes = [
managed_disk_id, virtual_machine_id
]
}
}