Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_account_[queue_properties|static_website] - Fix potential panics if the storage account is removed out of the band #28371

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ func (s AccountQueuePropertiesResource) Create() sdk.ResourceFunc {
if err != nil {
return err
}
if accountDetails == nil {
return fmt.Errorf("unable to locate %s", *accountID)
}

supportLevel := availableFunctionalityForAccount(accountDetails.Kind, accountTier, accountReplicationType)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (a AccountStaticWebsiteResource) Create() sdk.ResourceFunc {
if err != nil {
return err
}
if accountDetails == nil {
return fmt.Errorf("unable to locate %s", *accountID)
}

supportLevel := availableFunctionalityForAccount(accountDetails.Kind, accountTier, accountReplicationType)

Expand Down Expand Up @@ -158,7 +161,7 @@ func (a AccountStaticWebsiteResource) Read() sdk.ResourceFunc {
state.StorageAccountId = id.ID()

accountDetails, err := storageClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
if err != nil {
if err != nil || accountDetails == nil {
return metadata.MarkAsGone(id)
}

Expand Down Expand Up @@ -194,7 +197,7 @@ func (a AccountStaticWebsiteResource) Delete() sdk.ResourceFunc {
}

accountDetails, err := storageClient.FindAccount(ctx, id.SubscriptionId, id.StorageAccountName)
if err != nil {
if err != nil || accountDetails == nil {
return nil // lint:ignore nilerr If we don't find the account we can safely assume we don't need to remove the website since it must already be deleted
}

Expand Down Expand Up @@ -237,6 +240,9 @@ func (a AccountStaticWebsiteResource) Update() sdk.ResourceFunc {
if err != nil {
return err
}
if accountDetails == nil {
return fmt.Errorf("unable to locate %s", *id)
}

client, err := storageClient.AccountsDataPlaneClient(ctx, *accountDetails, storageClient.DataPlaneOperationSupportingAnyAuthMethod())
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/services/storage/storage_blob_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
Expand Down Expand Up @@ -572,6 +573,9 @@ func (r StorageBlobResource) Destroy(ctx context.Context, client *clients.Client
if err != nil {
return nil, fmt.Errorf("retrieving Account %q for Blob %q (Container %q): %+v", id.AccountId.AccountName, id.BlobName, id.ContainerName, err)
}
if account == nil {
return pointer.To(true), nil
}
blobsClient, err := client.Storage.BlobsDataPlaneClient(ctx, *account, client.Storage.DataPlaneOperationSupportingAnyAuthMethod())
if err != nil {
return nil, fmt.Errorf("building Blobs Client: %+v", err)
Expand Down
Loading