Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1894 #15281

Merged
merged 8 commits into from
Aug 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Purge Key Vaults after deleting resource group
  • Loading branch information
heaths authored and azure-sdk committed Aug 13, 2021
commit 34042f11a03cb0d6e0b222c25cef41a5ddbf4668
26 changes: 24 additions & 2 deletions eng/common/TestResources/Remove-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,38 @@ $verifyDeleteScript = {
}
}

# Get any Key Vaults that will be deleted so they can be purged later if soft delete is enabled.
$vaults = Get-AzKeyVault -ResourceGroupName "$ResourceGroupName" | ForEach-Object {
# Enumerating vaults from a resource group does not return all properties we required.
Get-AzKeyVault -VaultName $_.VaultName | Where-Object { $_.EnableSoftDelete }
}

# You may add additional resource checks that require the resource group to be deleted first before purging here.
$purgeRequired = !!$vaults

Log "Deleting resource group '$ResourceGroupName'"
if ($Force) {
if ($Force -and !$purgeRequired) {
Remove-AzResourceGroup -Name "$ResourceGroupName" -Force:$Force -AsJob
Write-Verbose "Running background job to delete resource group '$ResourceGroupName'"

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
}

# Purge any soft deleted vaults since there is now a limit per-subscription.
foreach ($vault in $vaults) {
Log "Attempting to purge Key Vault '$($vault.VaultName)'"

if ($vault.EnablePurgeProtection) {
# We will try anyway but will ignore errors
Write-Warning "Key Vault '$($vault.VaultName)' has purge protection enabled and may not be purged for $($vault.SoftDeleteRetentionInDays) days"
}

Remove-AzKeyVault -VaultName $vault.VaultName -Location $vault.Location -InRemovedState -Force -ErrorAction Ignore
}

$exitActions.Invoke()

<#
Expand Down