Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 1146 (#16968)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
azure-sdk and benbp authored Oct 29, 2020
1 parent 0cd5d1f commit f17590e
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions eng/common/TestResources/Remove-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -194,4 +216,4 @@ resource group whose name is stored in the environment variable
AZURE_RESOURCEGROUP_NAME.
.LINK
New-TestResources.ps1
#>
#>

0 comments on commit f17590e

Please sign in to comment.