Error to deploy an Azure image with datadisk

Hello,

I have the same incident related in the following topic without a resolution:

I have created an Azure Image which has an OS disk and a data disk attached. However, when I try to deploy that image via Terraform I got the following error:

│ Error: creating Linux Virtual Machine: (Name “myVM1298821” / Resource Group “non-prod”): compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request: StatusCode=400 – Original Error: Code=“InvalidParameter” Message=“StorageProfile.dataDisks.lun does not have required value(s) for image specified in storage profile.” Target=“storageProfile”

Is there any limitation or workaround for this error? Any suggestion is appreciated.

This is my main.tf file related:

data “azurerm_shared_image” “MusaReviewImage” {
name = “MusaReviewImage1”
gallery_name = “MusaReviewImage”
resource_group_name = “non-prod”

}

Create virtual machine

resource “azurerm_linux_virtual_machine” “my_terraform_vm” {
name = “myVM1298821”
location = var.location
resource_group_name = var.resourceGroupName
network_interface_ids = [azurerm_network_interface.my_terraform_nic.id]
size = “Standard_D2s_v3”
admin_username = “xxxx”
admin_password = “xxxx”
disable_password_authentication = false

os_disk {
name = “myOsDisk”
caching = “ReadWrite”
storage_account_type = “Premium_LRS”
}

source_image_id = “/subscriptions/e376b54a-c9bb-46cc-82e6-bde36010da8a/resourceGroups/non-prod/providers/Microsoft.Compute/galleries/MusaReviewImage/images/MusaReviewImage1/versions/0.0.1”

boot_diagnostics {
storage_account_uri = azurerm_storage_account.my_storage_account.primary_blob_endpoint
}
}

resource “azurerm_managed_disk” “dataDisk” {
name = “datadisk”
location = var.location
resource_group_name = var.resourceGroupName
storage_account_type = “StandardSSD_LRS”
create_option = “Empty”
disk_size_gb = 250

}

  resource "azurerm_virtual_machine_data_disk_attachment" "attachDisk" {
  managed_disk_id    = azurerm_managed_disk.dataDisk.id
  virtual_machine_id = azurerm_linux_virtual_machine.my_terraform_vm.id
  lun                = "10"
  caching            = "ReadWrite"
  depends_on = [
    azurerm_linux_virtual_machine.my_terraform_vm
  ]

}