More Info:
Ensure that a Microsoft Azure activity log alert is fired whenever a ‘Delete Virtual Machine’ event is triggered within your cloud account. An Azure activity log alert fires each time the action event that matches the condition specified in the alert configuration is triggered. The alert condition that this rule searches for isWhenever the Administrative Activity Log 'Delete Virtual Machine (Microsoft.Compute/virtualMachines)' has 'any' level, with 'any' status and event is initiated by 'any'
Risk Level
HighAddress
SecurityCompliance Standards
CBP, CIS Microsoft Azure FoundationsTriage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are step‑by‑step instructions to set up alerts for Delete Virtual Machine events in Azure using the Azure Portal (console).
This completes remediation: Azure will now generate alerts via the configured action group whenever a Delete Virtual Machine event occurs within your defined scope.
Goal
Create an Activity log alert that fires whenever a virtual machine is deleted.Step 1 – Open Monitor (Activity Log Alerts)
- Sign in to the Azure Portal: https://portal.azure.com
- In the left-hand menu, select Monitor.
- In the Monitor blade, click Alerts.
- Click + Create > Alert rule.
Step 2 – Select the Scope (Subscription / Resource Group)
- Under Scope, click Select scope.
- Choose one of:
- Entire subscription (to catch deletes for all VMs), or
- A specific resource group (only VMs in that RG).
- Click Apply.
Note: You generally cannot scope an activity log alert directly to a single VM, because delete events appear at subscription/RG level. Use subscription or RG scope.
Step 3 – Choose the Condition (Delete VM Operation)
- Under Condition, click Add condition.
- In the Signal type list, select Activity log (if not filtered already).
-
In the list of signals, find and select:
- Delete Virtual Machine (Microsoft.Compute/virtualMachines/delete)
(The exact wording may appear as an operation likeMicrosoft.Compute/virtualMachines/delete.)
- Delete Virtual Machine (Microsoft.Compute/virtualMachines/delete)
- Once selected, a configuration pane opens.
-
Optionally refine:
- Status =
Succeeded(to only alert when a delete actually completes).
- Status =
- Click Done.
Step 4 – Configure the Action Group (How You Get Notified)
If you already have an action group, you can reuse it; otherwise:- Under Actions, click + Add action groups.
- Click + Create action group.
- Fill in:
- Subscription and Resource group.
- Action group name and Display name.
- Under Notifications:
- Click + Add notification.
- Choose Email/SMS/Push/Voice.
- Provide email address (and/or phone, etc.).
- Click OK / Add.
- (Optional) Under Actions, you can add:
- ITSM, Webhook, Function, Logic App, etc.
- Click Review + create, then Create.
- Back in the alert rule, ensure the created Action group is selected.
- Click Apply.
Step 5 – Set Alert Rule Details
- Under Alert rule details:
- Alert rule name: e.g.
Alert - VM Deleted - Description: e.g.
Alert when any virtual machine delete operation succeeds. - Resource group: Choose where to store this alert rule’s metadata.
- Alert rule name: e.g.
- Set Severity:
- For deletions, choose something like Sev 2 (Error) or Sev 1 (Critical) depending on your policy.
- Ensure Enable rule upon creation is On.
Step 6 – Create the Alert Rule
- Click Review + create.
- Validate settings, then click Create.
Step 7 – (Optional) Test the Alert
- Delete a test VM in the chosen scope (subscription/RG).
- Once the delete completes (Activity log shows success), verify that:
- The alert is fired under Monitor > Alerts, and
- Notification (email/SMS/etc.) is received.
This completes remediation: Azure will now generate alerts via the configured action group whenever a Delete Virtual Machine event occurs within your defined scope.
Using CLI
Using CLI
Below is a minimal, end-to-end Azure CLI example to set up alerts for “Delete Virtual Machine” events in Azure (Compute). Adjust names/IDs as needed.
(Optional) Set the subscription:
This will be the notification target for the alert.
Notes:
You can test by deleting a test VM and confirming you receive the email from the action group.
1. Set basic variables
2. Create (or choose) a resource group
3. Create an Action Group (email notification)
4. Create an Activity Log Alert for VM delete events
This watches the Activity Log for the “Delete Virtual Machine” operation and fires the action group.category=Administrativetargets control-plane operations.operationName='Microsoft.Compute/virtualMachines/delete'is the VM delete event.status=Succeededensures alert only when deletion actually completes.--scopescan be narrowed to a specific resource group if you prefer (e.g./subscriptions/$SUBSCRIPTION_ID/resourceGroups/<rg-name>).
5. Verify the alert
List activity log alerts:Using Python
Using Python
Below are step‑by‑step remediation instructions and a Python example to create an Activity Log alert in Azure Monitor for VM delete events (
If you share how you authenticate to Azure (user vs service principal) and how you want alerts delivered (email, Teams, webhook), I can tailor the code and action group setup further.
Microsoft.Compute/virtualMachines/delete).1. What you will create
An Activity Log alert rule that fires when any VM is deleted in a chosen subscription, and sends a notification (e.g., email / action group).2. Prerequisites
- Azure CLI (for login / testing)
-
Python packages:
-
Permissions:
Monitoring Contributoror higher on the subscription (to create alert rule)Contributor(or similar) on the resource group where the alert will live
-
Authentication: one of:
az loginfor interactive user +DefaultAzureCredential- Or a Service Principal with
AZURE_CLIENT_ID,AZURE_TENANT_ID,AZURE_CLIENT_SECRETin env vars.
3. Decide the key parameters
Collect these values first:-
subscription_id– subscription where the VMs live -
resource_group_name– resource group to store the alert rule -
alert_rule_name– e.g."vm-delete-activity-log-alert" -
action_group_id– Resource ID of an existing Action Group (for email / webhook / etc.), e.g.:
4. Activity Log Alert Rule Definition
We want to create a rule with:-
Scope: the subscription
scope = f"/subscriptions/{subscription_id}" -
Condition:
- Category:
Administrative - Operation Name:
Microsoft.Compute/virtualMachines/delete - Status:
Succeeded(so only successful deletes trigger it)
- Category:
5. Python code to create the alert
6. Validate the alert
- Wait a few minutes after creating the rule.
- Delete a test VM in the subscription.
- Confirm:
- The Activity Log shows
Microsoft.Compute/virtualMachines/deletewith statusSucceeded. - The configured Action Group (e.g., email) receives a notification.
- The Activity Log shows
If you share how you authenticate to Azure (user vs service principal) and how you want alerts delivered (email, Teams, webhook), I can tailor the code and action group setup further.
Using Terraform
Using Terraform
terraform plan should show creation (or in-place update) of azurerm_monitor_activity_log_alert.VM_DELETE_ALERT (and azurerm_monitor_action_group.VM_DELETE_ACTION_GROUP if new), with criteria.operation_name set to "Microsoft.Compute/virtualMachines/delete".
