Sync eng/common directory with azure-sdk-tools for PR 1146 (#873)
* Remove resource group asynchronously and do not wait for completion * Verify resource group has reached Deleting state before exiting script * Use $_ instead of $Error[0] for resource group removal handling Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
This commit is contained in:
parent
36ea25db7f
commit
814a7b9203
@ -137,9 +137,31 @@ if (![string]::IsNullOrWhiteSpace($ServiceDirectory)) {
|
||||
}
|
||||
}
|
||||
|
||||
$verifyDeleteScript = {
|
||||
try {
|
||||
$group = Get-AzResourceGroup -name $ResourceGroupName
|
||||
} catch {
|
||||
if ($_.ToString().Contains("Provided resource group does not exist")) {
|
||||
Write-Verbose "Resource group '$ResourceGroupName' not found. Continuing..."
|
||||
return
|
||||
}
|
||||
throw $_
|
||||
}
|
||||
|
||||
if ($group.ProvisioningState -ne "Deleting")
|
||||
{
|
||||
throw "Resource group is in '$($group.ProvisioningState)' state, expected 'Deleting'"
|
||||
}
|
||||
}
|
||||
|
||||
Log "Deleting resource group '$ResourceGroupName'"
|
||||
if (Retry { Remove-AzResourceGroup -Name "$ResourceGroupName" -Force:$Force }) {
|
||||
Write-Verbose "Successfully deleted resource group '$ResourceGroupName'"
|
||||
if ($Force) {
|
||||
Remove-AzResourceGroup -Name "$ResourceGroupName" -Force:$Force -AsJob
|
||||
Retry $verifyDeleteScript 3
|
||||
Write-Verbose "Requested async deletion of resource group '$ResourceGroupName'"
|
||||
} else {
|
||||
# Don't swallow interactive confirmation when Force is false
|
||||
Remove-AzResourceGroup -Name "$ResourceGroupName" -Force:$Force
|
||||
}
|
||||
|
||||
$exitActions.Invoke()
|
||||
@ -194,4 +216,4 @@ resource group whose name is stored in the environment variable
|
||||
AZURE_RESOURCEGROUP_NAME.
|
||||
.LINK
|
||||
New-TestResources.ps1
|
||||
#>
|
||||
#>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user