Platform · Safe deletion

Demolition in Dependency Order: Safe, Re-runnable Offboarding

One workflow drains workloads, removes the GitOps and autoscaler layers, destroys infrastructure, returns network space, then cancels subscriptions, in the order that avoids orphans and stuck deletes.

  • GitHub Actions
  • Terraform
  • Vault
  • Python
  • FluxCD
  • CAST AI
  • Azure

// Overview

Offboarding is triggered from a form or manually. It reverses onboarding: it removes the app-bootstrap file so workloads are deleted gracefully, destroys the GitOps and autoscaler layers, destroys the infrastructure, releases network ranges, cancels subscriptions and resets Vault state. It handles HA (primary and secondary clusters) and lower, upper or both.

// The problem

Deleting a subscription or cluster out of order leaves orphaned load balancers, stuck cluster deletes, ghost registrations in the autoscaler dashboard, and reusable network ranges that collide with live networks.

// Flow

Demolition in Dependency Order: Safe, Re-runnable Offboarding flow1. Prepare → 2. Workload cleanup → 3. Destroy GitOps → 4. Destroy autoscaler → 5. Destroy infrastructure → 6. Gate: release network → 7. Side jobs → 8. Network watcher cleanup → 9. Destroy subscriptions → 10. Reset state01Prepare02Workload cleanup03Destroy GitOps04Destroy autoscaler05Destroy infrastructure06 · GATEGate: release network07Side jobs08Network watchercleanup09Destroy subscriptions10Reset state
  1. Prepareread Vault, check the cluster exists, detect HA, cache everything as an artifact
  2. Workload cleanupremove the bootstrap kustomization via auto-merged PR; wait for reconciliation
  3. Destroy GitOpsTerraform destroy of the Flux bootstrap root
  4. Destroy autoscalerTerraform destroy plus API cleanup, non-blocking
  5. Destroy infrastructurelower and upper roots destroyed in parallel
  6. Gate: release network gateranges returned to the pool only if destroys succeeded
  7. Side jobsremove lock, archive chat channels (non-blocking)
  8. Network watcher cleanupdelete the group created by policy outside Terraform
  9. Destroy subscriptionscancelled asynchronously by the cloud provider
  10. Reset statelock cleared and team removed from the registry

// Design decisions & guardrails

  • Artifact-based resilience: data is fetched once and cached for 90 days. Fallback chain: Vault, cached artifact, naming convention, then fail with recovery instructions.
  • Plan-destroy first; a Destroy-only action skips the plan for emergencies.
  • Every destroy job has a paired skip job that logs why it was skipped.
  • The network release guard prevents range reuse while a VNet may still exist.
  • Concurrency per team with cancel-in-progress off, so a running teardown is never interrupted.
  • continue-on-error is used only for optional jobs. Documented failure modes include stuck node resource groups, peering delete failures and Key Vault purge protection.

// Outcome

About ten numbered jobs, seven safety mechanisms and a pipeline that can be re-run after any failure.

// Related