Tear down: Lead-provisioned cohort (T+2)
Who: Students confirm their commits on main are pushed; the Team lead runs the cohort teardown workflow; the Lead repo admin removes the single pipeline identity.
When: T+2, after the event owner’s approval to tear down.
In Path B (Lead-provisioned cohort), student repositories (<event>-student-*) have no Member pipeline, gh-lab environment, or Azure OIDC identity. Students do not run any teardown workflow and do not run Remove-PlatformPipeline.ps1. Once students push their final commits on main from vm-dev01, the team lead tears down every student subscription and the shared foundation from <event>-lead in Azure Cloud Shell.
See Cost for when datacenter, SQL Managed Instance, and hub firewall charges stop.
Before running teardown
Section titled “Before running teardown”Confirm every item below before dispatching teardown in <event>-lead:
- Every student has committed and pushed all work on
main(app/ContosoUniversity,agent-output/university/, C9 scripts, andfactory/evidence/deliverables) fromC:\src\<your-repo>onvm-dev01and verified the commits on GitHub—teardown deletesvm-dev01. - The team lead has a private local backup of
<event>-lead/factory/.local/roster.jsonand.local/settings.jsonfor post-teardown verification (never committed to git). - The event owner has approved teardown and confirmed whether
rg-management(id-sqlmi-directory) should also be deleted (include-management=true) or kept for another event in the same tenant.
Allow time: about 20 minutes per wave without an archetype, or up to 2 hours when deleting SQL Managed Instances and releasing delegated subnets, followed by roughly 25 minutes for the shared foundation. Do not cancel a running job that looks quiet while SQL MI deletes; check the job log and Troubleshooting.
1. Tear down all member scopes and the shared foundation (Team lead)
Section titled “1. Tear down all member scopes and the shared foundation (Team lead)”Run commands in PowerShell (pwsh) from factory/ in <event>-lead (never from vm-dev01):
-
Standard cohort (up to 256 members): removes all
1..nmember scopes in parallel waves (MAX_PARALLEL, default20) and, only after every member scope succeeds, tears down the shared foundation (rg-hub,rg-managementwheninclude-management=true, policies, andmg-factory*management groups):Terminal window gh workflow run platform.yml `-f stage=teardown `-f members=all `-f confirm-team-teardown=true `-f include-management=true(Omit
-f include-management=trueonly when the event owner explicitly plans to reuserg-managementandid-sqlmi-directory’s Graph grant in the same tenant.) -
Large cohort (more than 256 members): stay within GitHub Actions’ 256-job matrix cap by tearing down member scopes in sequential index batches first (without
confirm-team-teardown), waiting for each batch to finish green before dispatching the next, and then removing the shared foundation with-f members=none:Terminal window gh workflow run platform.yml -f stage=teardown -f members=1-200Once
1-200finishes green:Terminal window gh workflow run platform.yml -f stage=teardown -f members=201-325After every member batch finishes green, finalize the shared foundation:
Terminal window gh workflow run platform.yml `-f stage=teardown `-f members=none `-f confirm-team-teardown=true `-f include-management=true
If any member job fails (for example, a lingering resource lock or subnet dependency), team foundation cleanup automatically halts so hub dependencies stay intact while you fix and re-run that index (-f stage=teardown -f members=<index>). Never force-delete a SQL Managed Instance subnet association.
2. Remove the single lead pipeline identity (Lead repo admin)
Section titled “2. Remove the single lead pipeline identity (Lead repo admin)”A workflow cannot delete the managed identity it is signed in as. Once the teardown workflow run is completely green, sign in from factory/ in <event>-lead as an administrator holding repo-admin on <event>-lead, Owner at Tenant Root (or the parent management group), and Owner on the shared services subscription:
az login --tenant '<tenant-id>' --use-device-codegh auth login --hostname github.com --git-protocol https --web./scripts/Remove-PlatformPipeline.ps1This single command removes id-factory-pipeline’s role assignments across Tenant Root, the shared subscription, and every workload subscription, deletes rg-cicd, removes the gh-lab environment and pipeline variables on <event>-lead, and verifies each item is gone. Nothing needs to be run on student repositories.
3. Verify cleanup and manage post-event repository retention
Section titled “3. Verify cleanup and manage post-event repository retention”-
Verify workload and shared resource groups are gone. From
factory/in<event>-lead, loop across.local/roster.jsonand.local/settings.json:Terminal window $s = Get-Content .local/settings.json | ConvertFrom-Json$roster = Get-Content .local/roster.json | ConvertFrom-Jsonforeach ($m in $roster) {$dc = az group exists --subscription $m.subscriptionId --name rg-datacenter$sp = az group exists --subscription $m.subscriptionId --name rg-spoke$un = az group exists --subscription $m.subscriptionId --name "rg-university-$($m.suffix)"[pscustomobject]@{ Index = $m.index; Datacenter = $dc; Spoke = $sp; Archetype = $un }}az group exists --subscription $s.sharedSubscriptionId --name rg-hubaz group exists --subscription $s.sharedSubscriptionId --name rg-cicdaz group exists --subscription $s.sharedSubscriptionId --name rg-managementEvery check must return
false(exceptrg-managementif you intentionally omittedinclude-management=true). Also confirm in the portal thatmg-factory*management groups, Azure Arc machine registrations, budgets, and kit-created role assignments are removed and workload subscriptions sit back in their return management group, and have the Entra group owner or directory admin delete<mgPrefix>-readers(or clear its membership for approved tenant reuse). -
Revoke temporary human privilege elevations. Only after
Remove-PlatformPipeline.ps1and the verification loop succeed, remove temporary human Owner assignments at Tenant Root, Global Administrator access elevation, and Privileged Role Administrator PIM activations. -
Archive or lock down student repositories per partner retention policy. Student repositories (
<org>/<event>-student-*) and<org>/<event>-student-templateremain in GitHub with each student’smaincommits preserved. Depending on your partner retention policy:- Archive
<event>-student-*repositories (gh repo archive <org>/<repo>) so evidence remains read-only for post-event review, or - Downgrade external Write (
push) collaborators to Read (pull) or remove outside collaborator access once attendees have exported any personal notes they are permitted to keep.
- Archive