Azure / aztfexport

A tool to bring existing Azure resources under Terraform's management
https://azure.github.io/aztfexport/
Mozilla Public License 2.0
1.59k stars 184 forks source link

Error: Cannot import "azurerm_virtual_machine_data_disk_attachment.res-8" #479

Closed novohool closed 10 months ago

novohool commented 10 months ago
aztfexport resource-group -f  --plain-ui=true --output-dir ${name}/${rgname} --non-interactive --hcl-only ${rgname}
Error: Cannot import non-existent remote object
While attempting to import an existing object to
"azurerm_virtual_machine_data_disk_attachment.res-8", the provider detected
that no object exists with the given id. Only pre-existing objects can be
imported; check that the id is correct and that it is associated with the
provider's configured region or endpoint, or use "terraform apply" to create
a new remote object for this resource.
novohool commented 10 months ago
{
    "name": "ase-01-02_datadisk_0",
    "id": "/subscriptions/35dc91e2-b065-48cd-a57c-xxx/resourceGroups/ASE/providers/Microsoft.Compute/disks/ase-01-02_datadisk_0",
    "type": "Microsoft.Compute/disks",
    "location": "eastasia",
    "managedBy": "/subscriptions/35dc91e2-b065-48cd-a57c-xxx/resourceGroups/ASE/providers/Microsoft.Compute/virtualMachines/ase-01-02",
    "sku": {
        "name": "Premium_LRS",
        "tier": "Premium"
    },
    "properties": {
        "creationData": {
            "createOption": "Empty"
        },
        "diskSizeGB": 128,
        "diskIOPSReadWrite": 500,
        "diskMBpsReadWrite": 100,
        "encryption": {
            "type": "EncryptionAtRestWithPlatformKey"
        },
        "networkAccessPolicy": "AllowAll",
        "publicNetworkAccess": "Enabled",
        "timeCreated": "2022-09-02T07:54:11.3765457+00:00",
        "provisioningState": "Succeeded",
        "diskState": "Attached",
        "diskSizeBytes": 137438953472,
        "uniqueId": "728833e3-48e1-4c2d-a020-xxx",
        "tier": "P10"
    }
}
stemaMSFT commented 10 months ago

Hey @novohool, it looks like you tried to export a data disk attachment, which does not exist as a support resource in the azurerm provider. You could attempt to re-expor this using the AzAPI provider with option --provider-name=azapi and see if that works instead.