From dfe176f6bcad10a6712667e68f03ae5c31cacb41 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Sat, 24 Oct 2020 12:08:27 +0200 Subject: [PATCH] fix lintrest issues --- ...esource_arm_backup_protected_file_share.go | 22 +++++++++++++------ ...ce_arm_backup_protected_file_share_test.go | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go index 3b0e59d128ff5..6b6374dbf99aa 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go @@ -98,22 +98,30 @@ func resourceArmBackupProtectedFileShareCreateUpdate(d *schema.ResourceData, met // The fileshare has a user defined name, but its system name (fileShareSystemName) is only known to Azure Backup filter := fmt.Sprintf("backupManagementType eq 'AzureStorage' and friendlyName eq '%s'", fileShareName) backupProtectableItemsResponse, err := protectableClient.List(ctx, vaultName, resourceGroup, filter, "") + if err != nil { + return fmt.Errorf("Error checking for protectable fileshares in Recovery Service Vault %q (Resource Group %q): %+v", vaultName, resourceGroup, err) + } backupProtectableItems := backupProtectableItemsResponse.Values() backupProtectedItemsResponse, err := protectedClient.List(ctx, vaultName, resourceGroup, filter, "") + if err != nil { + return fmt.Errorf("Error checking for protected fileshares in Recovery Service Vault %q (Resource Group %q): %+v", vaultName, resourceGroup, err) + } backupProtectedItems := backupProtectedItemsResponse.Values() + if backupProtectedItems == nil && backupProtectableItems == nil { + return fmt.Errorf("[ERROR] fileshare '%s' not found in protectable or protected fileshares, make sure Storage Account %q is registered with Recovery Service Vault %q (Resource Group %q)", fileShareName, accountName, vaultName, resourceGroup) + } + if len(backupProtectableItems)+len(backupProtectedItems) > 1 { + return fmt.Errorf("[ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected") + } + fileShareSystemName := "" if backupProtectableItems != nil && *backupProtectableItems[0].Name != "" { fileShareSystemName = *backupProtectableItems[0].Name - } else if backupProtectedItems != nil && *backupProtectedItems[0].Name != "" { - fileShareSystemName = *backupProtectedItems[0].Name - } else { - return fmt.Errorf("[ERROR] fileshare '%s' not found in protectable or protected fileshares, make sure ", fileShareName) } - - if len(backupProtectableItems)+len(backupProtectedItems) > 1 { - return fmt.Errorf("[ERROR] multiple fileshares found after filtering protectable or protected fileshares where only one is expected") + if backupProtectedItems != nil && *backupProtectedItems[0].Name != "" { + fileShareSystemName = *backupProtectedItems[0].Name } containerName := fmt.Sprintf("StorageContainer;storage;%s;%s", parsedStorageAccountID.ResourceGroup, accountName) diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go index dd914f517bd05..fb569f0675425 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go @@ -153,6 +153,9 @@ func testCheckAzureRMBackupProtectedFileShareExists(resourceName string) resourc } id, err := azure.ParseAzureResourceID(rs.Primary.ID) + if err != nil { + return fmt.Errorf("[ERROR] Unable to parse resource id '%s': %+v", rs.Primary.ID, err) + } fileShareSystemName := id.Path["protectedItems"] vaultName := rs.Primary.Attributes["recovery_vault_name"] storageID := rs.Primary.Attributes["source_storage_account_id"]