Skip to content

Commit

Permalink
fix azurerm_backup_protected_file_share Unable to Create Due to Azure…
Browse files Browse the repository at this point in the history
… Internal Error hashicorp#6762

azure file share backup protected item get by friendly name does not work in GA azure file share backups
instead, find the successfully created backup protected item with ProtectableItemsClient
  • Loading branch information
nkiraly committed Dec 16, 2020
1 parent 08c460a commit 55f430d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func resourceArmBackupProtectedFileShare() *schema.Resource {
func resourceArmBackupProtectedFileShareCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).RecoveryServices.ProtectedItemsClient
opClient := meta.(*clients.Client).RecoveryServices.BackupOperationStatusesClient
ableClient := meta.(*clients.Client).RecoveryServices.ProtectableItemsClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -143,13 +144,23 @@ func resourceArmBackupProtectedFileShareCreateUpdate(d *schema.ResourceData, met
return err
}

resp, err = client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "")
// #6762 azure file share backup protected item get by friendly name does not work in GA azure file share backups
// resp, err = client.Get(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, "")
// instead, find the successfully created backup protected item with ProtectableItemsClient
// List provides a pageable list of protectable objects within your subscription
page, err := ableClient.List(ctx, vaultName, resourceGroup, fmt.Sprintf("workloadType eq 'AzureFileShare' and friendlyName eq '%s'", protectedItemName), "")

if err != nil {
return fmt.Errorf("Error creating/udpating Azure File Share backup item %q (Vault %q): %+v", protectedItemName, vaultName, err)
}

id := strings.Replace(*resp.ID, "Subscriptions", "subscriptions", 1) // This code is a workaround for this bug https://github.com/Azure/azure-sdk-for-go/issues/2824
if page.Values() == nil {
return fmt.Errorf("Error listing Azure File Share backup item %q (Vault %q): %+v", protectedItemName, vaultName, err)
}

ableItem := page.Values()[0]

id := strings.Replace(*ableItem.ID, "Subscriptions", "subscriptions", 1) // This code is a workaround for this bug https://github.com/Azure/azure-sdk-for-go/issues/2824
d.SetId(id)

return resourceArmBackupProtectedFileShareRead(d, meta)
Expand Down
5 changes: 5 additions & 0 deletions azurerm/internal/services/recoveryservices/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type Client struct {
ProtectableItemsClient *backup.ProtectableItemsClient
ProtectedItemsClient *backup.ProtectedItemsClient
ProtectionPoliciesClient *backup.ProtectionPoliciesClient
BackupProtectionContainersClient *backup.ProtectionContainersClient
Expand All @@ -29,6 +30,9 @@ func NewClient(o *common.ClientOptions) *Client {
vaultsClient := recoveryservices.NewVaultsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&vaultsClient.Client, o.ResourceManagerAuthorizer)

protectableItemsClient := backup.NewProtectableItemsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&protectableItemsClient.Client, o.ResourceManagerAuthorizer)

protectedItemsClient := backup.NewProtectedItemsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&protectedItemsClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -78,6 +82,7 @@ func NewClient(o *common.ClientOptions) *Client {
}

return &Client{
ProtectableItemsClient: &protectableItemsClient,
ProtectedItemsClient: &protectedItemsClient,
ProtectionPoliciesClient: &protectionPoliciesClient,
BackupProtectionContainersClient: &backupProtectionContainersClient,
Expand Down

0 comments on commit 55f430d

Please sign in to comment.