Offboard Azure tenant with Entra ID only ↗
Follow this procedure to offboard a Microsoft Azure tenant that was onboarded with the Entra ID-only option and cleanly decommission all deployed resources.
Important
This offboarding script is designed for environments onboarded with BASE template version 1.0.10 or later. If your onboarding was deployed with an older BASE template version, this script may not fully remove all provisioned resources and could leave orphaned artifacts. Please verify your onboarding template version before proceeding.
Prerequisites
Before you begin, ensure you meet the following requirements:
Tooling Requirements
- Bash (version \(\ge\) 4.0)
- Azure CLI (version \(\ge\) 2.61)
- jq (JSON processor)
Working directory
You must run the offboarding script from the same directory where the files parameters.sh and graphAPIRoles.json are located. These files are packaged with the onboarding template:
parameters.sh: Contains configuration parameters (such asresource_suffix,tenant_id, andcustomer_object_id) which the script auto-loads at startup.graphAPIRoles.json: Defines the Microsoft Graph app role assignments to remove.
Required Azure permissions
The authenticated session must be run by a user or service principal with the following roles:
- Global Administrator: Required for managing Entra ID diagnostic settings and service principal operations.
- Owner: Required at the management group scope for deleting deployment stacks, role assignments, role definitions, and resource groups.
Authentication
Run the following command in your terminal to authenticate with the correct Azure tenant:
az login --tenant <tenant-id>
How to offboard Microsoft Azure with Entra ID only
Make the script executable
Set the execution permissions for the script within your working directory. In your local terminal within the directory containing your onboarding templates and configuration files, run:
chmod +x offboard_entra_id_only.sh
Run the offboard_entra_id_only.sh script
Run the offboarding script to clean up all deployed infrastructure. For your reference, the following flags are used in the script:
| Flag | Description |
--management-group-id <mg-id> | Required. Management group ID. Typically this is the tenant-root MG. |
--subscription-id <sub-id> | Required. The specific subscription hosting the onboarding resource group. |
--resource-suffix <rs> | The resource suffix from onboarding. This is automatically loaded from ./parameters.sh if present in the working directory. |
--no-dry-run | Action Flag. By default, the script runs in dry-run (read-only) mode. You must pass this flag to perform actual resource deletions. |
--yes or -y | Automation Flag. Skips the interactive confirmation prompt before a destructive run. |
--ext-resource-suffix <ext> | Override Flag. Overrides the automatic resolution of the extResourceSuffix. Required if the deployment stack has already been deleted and auto-resolution fails. |
-
First run a dry-run to preview the planned deletions and ensure your permissions are correct:
./offboard_entra_id_only.sh \ --management-group-id <mg-id> \ --subscription-id <sub-id>
-
After reviewing the dry-run output, run the script with
--no-dry-runto delete the resources:./offboard_entra_id_only.sh \ --management-group-id <mg-id> \ --subscription-id <sub-id> \ --no-dry-run
Verification and troubleshooting
Review the script output and confirm that all targeted resources were removed:
- Success: You will see a final confirmation message in your terminal indicating that cleanup is complete (Exit Code
0). - Leftover Resources: If the script times out or detects that any policy-deployed resources still remain, it will log the specific failed resources in the console output and exit with code
30. This is usually due to transient Azure API replication delays. You can safely re-run the cleanup script with the--no-dry-runflag to trigger another verification and cleanup sweep. See #reference-script-exit-codes for the exit code details.
Reference: Script exit codes
Use the following exit codes to understand the script results:
| Exit Code | Meaning |
0 | Success: Dry-run completed, or resources successfully deleted. |
10 | Preflight failure: Missing flags, authentication error, or extResourceSuffix unresolvable (pass --ext-resource-suffix). |
21 | Phase 1 (diagnostics) failure. |
22 | Phase 2 (stack) failure. |
23 | Phase 3 (onboarding RG) failure. (Note: Deletion is automatically skipped if a managed identity is found inside the Resource Group, indicating it is shared with a full tenant onboarding). |
24 | Phase 4 (graph-api-roles) failure. |
30 | Phase 5 (verify) failure: Leftover resources were detected. |
40 | Multiple failures: Two or more deletion phases failed. |
130 | Execution interrupted (SIGINT). |