Skip to content
Merged
Changes from all commits
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
41 changes: 41 additions & 0 deletions src/ALZ/Public/Remove-PlatformLandingZone.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function Remove-PlatformLandingZone {
being processed. Accepts both subscription IDs (GUIDs) and subscription names.
Default: Empty array (discover from management groups)

.PARAMETER AdditionalSubscriptions
An optional array of additional subscription IDs or names to include in the cleanup process. These subscriptions
will be merged with the subscriptions that are either discovered from management groups or explicitly provided
via the -Subscriptions parameter. This is useful for cleaning up bootstrap subscriptions or other subscriptions
that may sit outside the management group hierarchy being processed. Accepts both subscription IDs (GUIDs)
and subscription names.
Default: Empty array (no additional subscriptions)

.PARAMETER ResourceGroupsToRetainNamePatterns
An array of regex patterns for resource group names that should be retained (not deleted). Resource groups
matching any of these patterns will be skipped during the deletion process. This is useful for preserving
Expand Down Expand Up @@ -136,6 +144,20 @@ function Remove-PlatformLandingZone {
containing "alz" anywhere in their name).
Default: Empty array (delete all deployment stacks)

.EXAMPLE
Remove-PlatformLandingZone -ManagementGroups @("alz-test") -AdditionalSubscriptions @("Bootstrap-Sub-001")

Processes the "alz-test" management group hierarchy, discovers subscriptions from the management groups,
and also includes the "Bootstrap-Sub-001" subscription in the cleanup process. This is useful when the
bootstrap subscription sits outside the management group hierarchy being processed.

.EXAMPLE
Remove-PlatformLandingZone -ManagementGroups @("alz-test") -Subscriptions @("Sub-Test-001") -AdditionalSubscriptions @("12345678-1234-1234-1234-123456789012")

Processes the "alz-test" management group hierarchy and cleans up both the explicitly provided subscription
"Sub-Test-001" and the additional subscription specified by GUID. The additional subscriptions are merged
with the provided subscriptions for resource group deletion.

.EXAMPLE
Remove-PlatformLandingZone -ManagementGroups @("alz-platform", "alz-landingzones")

Expand Down Expand Up @@ -284,6 +306,7 @@ function Remove-PlatformLandingZone {
[switch]$DeleteTargetManagementGroups,
[string]$SubscriptionsTargetManagementGroup = $null,
[string[]]$Subscriptions = @(),
[string[]]$AdditionalSubscriptions = @(),
[string[]]$ResourceGroupsToRetainNamePatterns = @(
"VisualStudioOnline-" # By default retain Visual Studio Online resource groups created for Azure DevOps billing purposes
),
Expand Down Expand Up @@ -1155,6 +1178,24 @@ function Remove-PlatformLandingZone {
}
}

# Add additional subscriptions to the discovered/supplied subscriptions
if($AdditionalSubscriptions.Count -gt 0) {
Write-ToConsoleLog "Processing additional subscriptions to merge with discovered/supplied subscriptions..."

foreach($subscription in $AdditionalSubscriptions) {
$subscriptionObject = @{
Id = (Test-IsGuid -StringGuid $subscription) ? $subscription : (az account list --all --query "[?name=='$subscription'].id" -o tsv)
Name = (Test-IsGuid -StringGuid $subscription) ? (az account list --all --query "[?id=='$subscription'].name" -o tsv) : $subscription
}
if(-not $subscriptionObject.Id -or -not $subscriptionObject.Name) {
Write-ToConsoleLog "Additional subscription not found, skipping: $subscription" -IsWarning
continue
}
Write-ToConsoleLog "Adding additional subscription: $($subscriptionObject.Name) (ID: $($subscriptionObject.Id))" -NoNewLine
$subscriptionsFound.Add($subscriptionObject)
}
}

$subscriptionsFinal = $subscriptionsFound.ToArray() | Sort-Object -Property name -Unique

if($subscriptionsFinal.Count -eq 0) {
Expand Down
Loading