diff --git a/eng/common/scripts/Helpers/Resource-Helpers.ps1 b/eng/common/scripts/Helpers/Resource-Helpers.ps1 index f12b35503500..35f3ec23b87e 100644 --- a/eng/common/scripts/Helpers/Resource-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Resource-Helpers.ps1 @@ -297,7 +297,8 @@ function Remove-WormStorageAccounts() { [CmdletBinding(SupportsShouldProcess = $True)] param( [string]$GroupPrefix, - [switch]$CI + [switch]$CI, + [bool]$CheckPrefix = $true ) $ErrorActionPreference = 'Stop' @@ -306,10 +307,16 @@ function Remove-WormStorageAccounts() { # DO NOT REMOVE THIS # We call this script from live test pipelines as well, and a string mismatch/error could blow away # some static storage accounts we rely on - if (!$groupPrefix -or ($CI -and (!$GroupPrefix.StartsWith('rg-') -and !$GroupPrefix.StartsWith('SSS3PT_rg-')))) { - throw "The -GroupPrefix parameter must not be empty, or must start with 'rg-' or 'SSS3PT_rg-' in CI contexts" + # Note: Prefix check can be disabled via `-CheckPrefix:$false` for scenarios where the resource group prefix isn't standardized. + if (!$GroupPrefix) { + throw "The -GroupPrefix parameter must not be empty" } + if ($CheckPrefix -and $CI -and (!$GroupPrefix.StartsWith('rg-') -and !$GroupPrefix.StartsWith('SSS3PT_rg-'))) { + throw "In CI contexts with -CheckPrefix enabled, -GroupPrefix must start with 'rg-' or 'SSS3PT_rg-'" + } + + $groups = Get-AzResourceGroup | Where-Object { $_.ResourceGroupName.StartsWith($GroupPrefix) } | Where-Object { $_.ProvisioningState -ne 'Deleting' } foreach ($group in $groups) {