azurerm_backup_protected_vm not being exported (Backup Items from an Azure Recovery Service Vault)
I am working with Azure Recovery Service Vault and I found the backup items are not being exported by the aztfexport process. Those resources are not in the aztfexportSkippedResources, so it seems those resource types are being ignored.
I was able to add into the terraform project/state by importing it with the next sentences:
import {
id = "/subscriptions/xxxx03xx-4xx0-4xxb-9xxx-XXXXXcbdxxxxx/resourceGroups/rg-XXXXX-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-XXXXXXX-scus-Prod-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;maz-wss-rg-01;vm-XXXXXXX/protectedItems/VM;iaasvmcontainerv2;maz-wss-rg-01;vm-XXXXXX"
to = azurerm_backup_protected_vm.pvm-11
}
resource "azurerm_backup_protected_vm" "pvm-11" {
resource_group_name = azurerm_resource_group.res-0.name
recovery_vault_name = azurerm_recovery_services_vault.res-1.name
source_vm_id = "/subscriptions/xxxx03xx-4xx0-4xxb-9xxx-XXXXXcbdxxxxx/resourceGroups/xxxz-xx-rg-01/providers/Microsoft.Compute/virtualMachines/vm-XXXXXX"
backup_policy_id = azurerm_backup_policy_vm.res-5.id
}
@edsonestrella Can you try the resource mode to directly export this resource:
aztfexport resource <options> "/subscriptions/xxxx03xx-4xx0-4xxb-9xxx-XXXXXcbdxxxxx/resourceGroups/rg-XXXXX-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-XXXXXXX-scus-Prod-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;maz-wss-rg-01;vm-XXXXXXX/protectedItems/VM;iaasvmcontainerv2;maz-wss-rg-01;vm-XXXXXX"
If this works for you, the issue can be narrowed down to azlist.
@magodo , Sorry I did not analyze correctly at the beginning. This resource type is being skiped.
aztfexport resource --non-interactive --generate-mapping-file --plain-ui '/subscriptions/3db0333a-4440-470b-9a88-6053cbd20bfb/resourceGroups/rg-SharedServicesBackup-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-SharedServicesBackup-scus-Pro
d-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01/protectedItems/VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01","VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01'
[aztfexport] 2025/03/20 17:08:45 Initializing...
[aztfexport] 2025/03/20 17:09:21 Listing resources...
[aztfexport] 2025/03/20 17:09:25 Exporting Skipped Resource file...
[aztfexport] 2025/03/20 17:09:25 Exporting Resource Mapping file...
[aztfexport] 2025/03/20 17:09:25 DeInitializing...
PS C:\...\aztfexport-Issue607>
aztfezxportResourceMapping.json:
{}
aztfexportSkippedResources.txt:
Following resources are marked to be skipped:
- /subscriptions/3db0333a-4440-470b-9a88-6053cbd20bfb/resourceGroups/rg-SharedServicesBackup-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-SharedServicesBackup-scus-Prod-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01/protectedItems/VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01","VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01
@edsonestrella Did you specified the wrong resource id?
Shouldn't it be:
/subscriptions/3db0333a-4440-470b-9a88-6053cbd20bfb/resourceGroups/rg-SharedServicesBackup-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-SharedServicesBackup-scus-Prod-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01/protectedItems/VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01
instead of:
/subscriptions/3db0333a-4440-470b-9a88-6053cbd20bfb/resourceGroups/rg-SharedServicesBackup-scus-Prod/providers/Microsoft.RecoveryServices/vaults/rv-SharedServicesBackup-scus-Prod-01/backupFabrics/Azure/protectionContainers/IaasVMContainer;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01/protectedItems/VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01","VM;iaasvmcontainerv2;rg-cloudops-scus-prod;vm-CloudOps-scus-Prod-01
(Note the " and the tailing part)
E.g. I have created a azurerm_backup_protected_vm based on the azurerm provider's basic test case of this resource, and can successfully export it using aztfexport:
$ aztfexport resource '/subscriptions/xxxx/resourceGroups/acctestRG-backup-321/providers/Microsoft.RecoveryServices/vaults/acctest-321/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;acctestRG-backup-321;acctestvm/protectedItems/VM;iaasvmcontainerv2;acctestRG-backup-321;acctestvm'
$ tf show
# azurerm_backup_protected_vm.res-0:
resource "azurerm_backup_protected_vm" "res-0" {
backup_policy_id = "/subscriptions/xxxx/resourceGroups/acctestRG-backup-321/providers/Microsoft.RecoveryServices/vaults/acctest-321/backupPolicies/acctest-321"
id = "/subscriptions/xxxx/resourceGroups/acctestRG-backup-321/providers/Microsoft.RecoveryServices/vaults/acctest-321/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;acctestRG-backup-321;acctestvm/protectedItems/VM;iaasvmcontainerv2;acctestRG-backup-321;acctestvm"
include_disk_luns = [
0,
]
protection_state = "IRPending"
recovery_vault_name = "acctest-321"
resource_group_name = "acctestRG-backup-321"
source_vm_id = "/subscriptions/xxxx/resourceGroups/acctestRG-backup-321/providers/Microsoft.Compute/virtualMachines/acctestvm"
}
```