Cleanup & Reset

Two different cleanups, and they are not interchangeable. One stops Azure charging you. The other takes the lab off your laptop.

[!CAUTION] Order matters. Tear down Azure first, then clear credentials. Once you are signed out you can no longer delete anything β€” and Azure Firewall, Bastion, Front Door and SQL keep billing at roughly $1.84/hr with the full stack up.

Β  What it removes How
1 Β· Azure Everything the labs deployed Classroom: the Teardown labs workflow Β· Self-hosted: Cleanup-Labs.ps1
2 Β· This machine az and gh sign-ins, saved settings, your passwords file Clear-LabCredentials.ps1 (self-hosted / CLI path)

1. Tear down Azure

Classroom β€” the Teardown workflow

On your fork: Actions β†’ Teardown labs β†’ Run workflow. It defaults to a dry run that only lists what would be deleted; to delete for real, un-check dry run and type DELETE into the confirmation input.

That workflow is your teardown path, full stop: your account holds Reader on the resource group, so Cleanup-Labs.ps1 (which deletes resources directly with your own credentials) cannot work for you β€” it is a self-hosted tool. The workflow deletes under your workshop deploy identity instead, targeting the group named after your fork owner. The group itself always stays.

Self-hosted β€” the script

Preview first β€” it lists what would go and changes nothing:

./scripts/Cleanup-Labs.ps1 -ResourceGroup $env:AZURE_RESOURCE_GROUP -WhatIf
./scripts/Cleanup-Labs.ps1 -ResourceGroup $env:AZURE_RESOURCE_GROUP

You should see: the resources deleted in three passes, then a report of anything that survived. It deletes the contents of the group and leaves the group itself. (The Teardown workflow works for self-hosted forks too.)

Also removing the Entra app registration your own setup created:

./scripts/Cleanup-Labs.ps1 -Prefix "<yourname>" -RemoveOidc

[!WARNING] -RemoveOidc is for self-hosted setups only β€” in the classroom, removing the Entra app is instructor-only. The classroom deploy identity is not an app registration: it is a managed identity in the instructor’s environment, removed by the instructor’s teardown after class. Instructors: see Instructor Admin Tools.

[!WARNING] Do not delete only the Azure Firewall. After L1.2, both spoke subnets route 0.0.0.0/0 at its private IP. Removing it alone black-holes every VM’s outbound traffic while they keep billing. Tear down all of L1.2, route table included, or run the full teardown.


2. Clear this machine

Skip this on a classroom laptop that gets reimaged. Do it if you ran the labs on your own machine.

./scripts/Clear-LabCredentials.ps1 -WhatIf   # preview
./scripts/Clear-LabCredentials.ps1

It checks for still-deployed resources before signing you out, and stops to ask if it finds any.

What the labs put on your machine

Left behind Where Removed by
Azure sign-in token ~/.azure token cache Clear-LabCredentials.ps1
GitHub sign-in token gh config (hosts.yml) Clear-LabCredentials.ps1
Your prefix, region, resource group User environment variables (Windows) Clear-LabCredentials.ps1, or Load-LabSettings.ps1 -Clear
VM and SQL passwords User environment variables (Windows), and lab-settings.csv Both of the above
GitHub Desktop / VS Code sign-in Each app’s own store You β€” sign out in the app

Only clearing the saved settings, staying signed in:

./scripts/Load-LabSettings.ps1 -Clear

[!IMPORTANT] -Persist writes your lab passwords to disk in plain text. On Windows they go to the registry under HKCU\Environment and stay until removed. That is a deliberate convenience for a throwaway lab, not a habit to carry to work β€” real credentials belong in a secret store, which is exactly what the OIDC path in these labs demonstrates.

This workshop is Windows 11 only. On macOS or Linux -Persist does nothing at all β€” only Windows has a user environment store for it to write to β€” so there is nothing stored to clean up there either. The script says so rather than pretending. lab-settings.csv is the persistence in that case: re-run ./scripts/Load-LabSettings.ps1 per terminal.


Useful commands

Where am I signed in?

az account show --query "{subscription:name, user:user.name}" -o table
gh auth status

What is still deployed, and what is it costing?

az resource list -g $env:AZURE_RESOURCE_GROUP --query "[].{name:name, type:type}" -o table
az resource list -g $env:AZURE_RESOURCE_GROUP --query "length(@)"

Reload settings in a new terminal

./scripts/Load-LabSettings.ps1

Why did a deployment fail?

$RG = $env:AZURE_RESOURCE_GROUP
az deployment group list -g $RG --query "[?properties.provisioningState=='Failed'].[name]" -o tsv
az deployment group show -g $RG --name <deployment-name> --query properties.error

Start the whole workshop over

Classroom: run the Teardown labs workflow (dry run β†’ DELETE), then simply run L1.1 again. There is nothing to re-run or re-wire β€” the deploy identity lives in the workflow code and the federated trust, not in your fork.

Self-hosted: teardown, then re-run setup:

./scripts/Cleanup-Labs.ps1 -ResourceGroup $env:AZURE_RESOURCE_GROUP
./scripts/Setup-Oidc.ps1 -ResourceGroup $env:AZURE_RESOURCE_GROUP -Prefix "<yourname>"



GitHub feature spotlight Β· Manual approval as a safety interlock

You just used it: the Teardown labs workflow will not delete anything until you type DELETE into the input box. It is workflow_dispatch with a required input, and it defaults to a dry run. Find it: .github/workflows/teardown.yml β€” the inputs.confirm block and the step that checks it. Beyond the lab: the destructive button and the confirmation should never be the same click. A typed confirmation costs three seconds and is the cheapest guard you can put in front of an irreversible action. Docs β†’