From 100254c1da47e018c124b215b38856a75b903036 Mon Sep 17 00:00:00 2001 From: Wes Haggard Date: Mon, 8 Jan 2024 14:32:18 -0800 Subject: [PATCH] Fix storage account clean up (#7496) * Revert "Add extra handling for errors during clean-up" This reverts commit 3eb8cb73298b0e9c74479b1400bd89d5d3650f26. * Skip container clean-up for file storage accounts as it has none --- eng/scripts/Remove-WormStorageAccounts.ps1 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/eng/scripts/Remove-WormStorageAccounts.ps1 b/eng/scripts/Remove-WormStorageAccounts.ps1 index 022e81d281e..841da052741 100644 --- a/eng/scripts/Remove-WormStorageAccounts.ps1 +++ b/eng/scripts/Remove-WormStorageAccounts.ps1 @@ -24,15 +24,19 @@ foreach ($group in $groups) { } else { Write-Host "Removing $($account.StorageAccountName) in $($account.ResourceGroupName)" } + + $hasContainers = ($account.Kind -ne "FileStorage") + + # If it doesn't have containers then we can skip the explicit clean-up of this storage account + if (!$hasContainers) { continue } + $ctx = New-AzStorageContext -StorageAccountName $account.StorageAccountName + + $immutableBlobs = $ctx ` + | Get-AzStorageContainer ` + | Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } ` + | Get-AzStorageBlob try { - # Sometimes the retrieval here fails in preview/dogfood regions but we should still try to delete the storage account below - # so just handle the exception and attempt the delete below. - $immutableBlobs = $ctx ` - | Get-AzStorageContainer ` - | Where-Object { $_.BlobContainerProperties.HasImmutableStorageWithVersioning } ` - | Get-AzStorageBlob - foreach ($blob in $immutableBlobs) { Write-Host "Removing legal hold - blob: $($blob.Name), account: $($account.StorageAccountName), group: $($group.ResourceGroupName)" $blob | Set-AzStorageBlobLegalHold -DisableLegalHold | Out-Null