LabBuilder - CleanUp #105
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "LabBuilder - CleanUp" | |
on: | |
workflow_dispatch: | |
workflow_call: | |
permissions: | |
id-token: write | |
jobs: | |
removeResources: | |
name: "Remove LabBuilder resources" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Azure Login | |
id: login | |
uses: azure/login@v2 | |
with: | |
enable-AzPSSession: true | |
client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
- name: Cleanup | |
uses: azure/powershell@v2 | |
with: | |
azPSVersion: 'latest' | |
inlineScript: | | |
Write-Host "List of Resource groups to be deleted...." | |
$resourceGroups = Get-AzResourceGroup -Tag @{ LabBuilder = "validation" } | |
if ($resourceGroups.Count -eq 0) { | |
Write-Host "No resource groups found to delete." -ForegroundColor Yellow | |
Write-Host "Exiting without deleting anything." -ForegroundColor Yellow | |
exit 0 | |
} else { | |
Write-Host "Found $($resourceGroups.Count) resource groups to deleted:" | |
$resourceGroups | Format-Table -Property ResourceGroupName, Location, Tags | |
Write-Host "Removing Resource groups..." | |
foreach ($rg in $resourceGroups) { | |
Remove-AzResourceGroup -Name $rg.ResourceGroupName -Force -AsJob | |
} | |
} | |