Skip to content

Commit

Permalink
support purge
Browse files Browse the repository at this point in the history
  • Loading branch information
KSchlobohm committed Mar 13, 2024
1 parent 291d162 commit 35214bf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions testscripts/cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Param(
[Parameter(Mandatory = $false)][string]$SecondarySpokeResourceGroup,
[Parameter(Mandatory = $false)][string]$HubResourceGroup,
[Parameter(Mandatory = $false)][switch]$SkipResourceGroupDeletion,
[Parameter(Mandatory = $false)][switch]$Purge,
[Parameter(Mandatory = $false)][switch]$NoPrompt
)

Expand Down Expand Up @@ -275,6 +276,10 @@ if (Test-EntraAppRegistrationExists -Name $calculatedAppRegistrationNameForFront
$appRegistrations.Add($calculatedAppRegistrationNameForFrontend) | Out-Null
}

# Determine if we need to purge the App Configuration and Key Vault.
$defaultPurgeResources = if ($Purge) { "y" } else { "n" }
$purgeResources = Read-ApplicationPrompt -Prompt "Do you wish to puge resources that cannot be reassigned immediately (such as Key Vault)? [y/n]" -DefaultValue $defaultPurgeResources -NoPrompt:$NoPrompt

# press enter to proceed
if (-not $NoPrompt) {
"`nPress enter to proceed with cleanup or CTRL+C to cancel" | Write-Output
Expand All @@ -290,6 +295,25 @@ if ($azdConfig['AZURE_PRINCIPAL_TYPE'] -eq 'User') {
}
}

if ($purgeResources -eq "y") {
"> Remove and purge purgeable resources:" | Write-Output
foreach ($resourceGroupName in $resourceGroups) {
Get-AzKeyVault -ResourceGroupName $resourceGroupName | Foreach-Object {
"`tRemoving $($_.VaultName)" | Write-Output
Remove-AzKeyVault -VaultName $_.VaultName -ResourceGroupName $resourceGroupName -Force
"`tPurging $($_.VaultName)" | Write-Output
Remove-AzKeyVault -VaultName $_.VaultName -Location $_.Location -InRemovedState -Force -ErrorAction SilentlyContinue
}

Get-AzAppConfigurationStore -ResourceGroupName $resourceGroupName | Foreach-Object {
"`tRemoving $($_.Name)" | Write-Output
Remove-AzAppConfigurationStore -Name $_.Name -ResourceGroupName $resourceGroupName
"`tPurging $($_.Name)" | Write-Output
Clear-AzAppConfigurationDeletedStore -Location $_.Location -Name $_.Name -ErrorAction SilentlyContinue
}
}
}

"`nRemoving resources from resource groups..." | Write-Output
"> Private Endpoints:" | Write-Output
foreach ($resourceGroupName in $resourceGroups) {
Expand Down

0 comments on commit 35214bf

Please sign in to comment.