Skip to content

Commit

Permalink
fix lintrest issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Oct 24, 2020
1 parent e86829d commit dfe176f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit dfe176f

Please sign in to comment.