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:
Azure SDK Bot 2020-10-29 16:25:21 -07:00 committed by GitHub
parent 36ea25db7f
commit 814a7b9203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
#>
#>