For the complete documentation index, see llms.txt. This page is also available as Markdown.
Cortex Cloud Runtime

Offboard Azure management group or tenant scope (ARM)

How to offboard Microsoft Azure management group or tenant scopes from Cortex Cloud: A step-by-step technical guide to safely removing all Azure resources deployed by Cortex onboarding templates.

Follow this procedure to offboard a Microsoft Azure Management Group or Tenant scope from Cortex Cloud and cleanly decommission all deployed resources.

Important

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 as resource_suffix, tenant_id, and customer_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, policy resources, role assignments, role definitions, and resource groups.

Authentication

Run the following command in your terminal to authenticate with the correct Azure tenant:

How to offboard Microsoft Azure MG or tenant scope - ARM method

1

Gather required values

Before running the offboarding script, collect the following values:

Variable
Description
Where to find it

<mg-id>

The management group ID being offboarded.

Azure portal > Management groups, or run az account management-group list -o table.

<tenant-root-mg-id>

The tenant-root management group ID (for tenant scope only). Typically matches your Azure tenant ID.

Azure portal > Management groups > the top-level group, or run az account management-group list -o table.

<sub-id>

The subscription ID hosting the Cortex onboarding resource group (cortex-onboarding-<resource_suffix>).

Azure portal > Subscriptions, or run az account list -o table.

2

Locate your offboarding bundle

Navigate to the directory containing these files before proceeding. The bundle contains the following files, which must all be present in the same directory:

File
Description

parameters.sh

Connector-specific parameters, including resource_suffix, tenant_id, and customer_object_id. Auto-loaded by the script at startup.

graphAPIRoles.json

Defines which Microsoft Graph app role assignments to remove.

offboard_mg_tenant.sh

Interactive offboarding script.

3

Understand the offboarding phases

The script executes the following phases in a fixed order. In dry-run mode, each phase lists the resources it would delete without making any changes. In action mode, each phase deletes the identified resources and the final phase verifies that all resources have been removed.

Script phase
What it does

diagnostics

Deletes the management group diagnostic setting. For tenant scope, also deletes the Entra ID diagnostic setting.

stack

Deletes the deployment stack cortex-policy-<resource_suffix> at management group scope.

onboarding-rg

Deletes the onboarding resource group cortex-onboarding-<resource_suffix>, which cascades deletion of the managed identity.

graph-api-roles

Removes Microsoft Graph app role assignments from the customer service principal.

policy

Deletes per-subscription policy-deployed resources across all child subscriptions: role assignments, role definitions, and the policy resource group.

verify

Confirms all targeted resources are gone. Skipped in dry-run mode.

4

Run the offboard_mg_tenant.sh script in dry-run mode

First, run the script in dry-run mode (the default) to preview all resources that would be deleted and verify your permissions are correct. No changes are made during a dry run.

For management group scope, run:

For tenant scope run:

Review the dry-run output carefully and confirm that the listed resources are correct before proceeding.

5

Run the offboarding cleanup

After reviewing the dry-run output, run the script with --no-dry-run to delete the resources.

For a management group scope connector:

For a tenant scope connector:

6

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-run flag to trigger another verification and cleanup sweep. See Reference: Script exit codes for the exit code details.

Troubleshooting

The deployment stack was already deleted

If the deployment stack was deleted manually or in a prior partial run, the script cannot auto-resolve the extResourceSuffix and exits with code 10. The value of <ext-value> is printed in the logs when you run the offboard script. Pass the --ext-resource-suffix flag with that value to resume:

Verification fails after the action

The script automatically re-runs the cleanup and re-verifies up to three times. Transient Azure API delays are the most common cause. If issues persist after three attempts, inspect the remaining resources using the IDs shown in the verification output and re-run the script with --no-dry-run to trigger another cleanup sweep.

Reference: Script exit codes

Use the following exit codes to understand the script results:

Code
Meaning

0

Success, dry-run completed, or nothing to delete

10

Preflight failure (missing flag, authentication error, or extResourceSuffix unresolvable. Pass --ext-resource-suffix)

21–25

Single phase failure (diagnostics / stack / onboarding-rg / graph-api-roles / policy)

30

Verification found leftover resources

40

Two or more phases failed

130

Interrupted (SIGINT)

Last updated

Was this helpful?