Closed 825i closed 1 month ago
@825i I've tried to create a VM with a data disk attached, and the tool can successfully export them.
Would you please try run terraform import
to import the azurerm_virtual_machine_data_disk_attachment
?
If this still gives the same error, then could you try to check the name of the disk appears in the VM's API model and in the resource id are case sensitively identical, as the provider has the following logic when reading (during import) the data disk attachment:
virtualMachine, err := client.Get(ctx, id.ResourceGroup, id.VirtualMachineName, "")
if err != nil {
if utils.ResponseWasNotFound(virtualMachine.Response) {
log.Printf("[DEBUG] Virtual Machine %q was not found (Resource Group %q) therefore Data Disk Attachment cannot exist - removing from state", id.VirtualMachineName, id.ResourceGroup)
d.SetId("")
return nil
}
return fmt.Errorf("loading Virtual Machine %q : %+v", id.String(), err)
}
var disk *compute.DataDisk
if profile := virtualMachine.StorageProfile; profile != nil {
if dataDisks := profile.DataDisks; dataDisks != nil {
for _, dataDisk := range *dataDisks {
// since this field isn't (and shouldn't be) case-sensitive; we're deliberately not using `strings.EqualFold`
if *dataDisk.Name == id.Name {
disk = &dataDisk
break
}
}
}
}
I have no idea how to use terraform import
but it seems like maybe the disk did get added as this resource (res 4)? As there is no other appdisk0
only one.
resource "azurerm_managed_disk" "res-4" {
create_option = var.create_option
location = var.location
name = "appdisk0"
resource_group_name = var.resource_group_name
storage_account_type = var.storage_account_type
zone = var.zone
}
EDIT: Ok, now I think I understand what the problem was (maybe). There is no VM called appdisk0
there is only a logical disk called appdisk0
. Or now I am just really even more confused.
I'll try and learn a bit how to use terraform import
and see if that works. It's not such a big deal though because it's just a single disk.
Ok so I couldn't really get anywhere with Terraform import but it does seem that the disk was scoped in anyway during the initial run. However, it was given a different resource number for some reason. Instead of res-4 it became res-8. No idea why.
So the error message was actually a false positive.
Please note that this is not the azurerm_managed_disk
, but the azurerm_virtual_machine_data_disk_attachment
, which is a virtual attachment resource to associate the azurerm_managed_disk
and the azurerm_linux_virtual_machine
resources.
:wave:
Since we've not heard back here I'm going to close this issue for the moment. Feel free to reopen if still have questions.
I tried to export a resource group and 74/75 resources completed successfully which is amazing. However, one disk I never suspected would be a problem, has failed. The error message below also doesn't explain much, as it is also wrong.
This resource absolutely does exist, as shown below:
Any idea why it failed to be recognized and exported? This should have been business as usual.
I'm using:
aztfexport version v0.14.0(fb772ba)
and:Terraform v1.7.0 on linux_amd64
with:I found #440
and tried the instructions there to list the resources via AzureCLI first. Here is the failed
appdisk0
resource listed:I tried also
--use-azure-cli-cred
and this too: https://github.com/Azure/aztfexport/issues/440#issuecomment-1678592219 Sadly neither have helped with this disk.Could someone please suggest some more things to try?