Hi @Winnie Yap ,
Yes, it is possible to stop or deallocate resources in Azure when a cost threshold is exceeded, but there are important caveats and limitations depending on the resource type. Here's a structured breakdown of how you can achieve this:
Overall Strategy Create a Budget Alert in Azure Cost Management.
Trigger an Action Group on budget threshold breach.
Use Automation (Runbook, Logic App, or Azure Function) as the action group target.
Runbook stops IaaS resources (like VMs, SQL VMs).
PAAS & SAAS services limitations (some cannot be "stopped"—only deleted or scaled down).
step-by-Step Implementation Guide
1. Create a Budget with Alert Go to Cost Management + Billing > Budgets > Create a new budget at the Subscription level.
Set a threshold (e.g., 80%) and define Action Group to be triggered on that threshold.
2. Action Group Setup In Azure Monitor > Alerts > Action groups, create a new group.
Add an Azure Automation Runbook (or Logic App) as the action.
3. Automation Runbook Create a PowerShell Runbook in an Azure Automation Account. Example code:
$vmList = Get-AzVM
foreach ($vm in $vmList) {
if ($vm.PowerState -ne "VM deallocated") {
Stop-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Force
}
}
Limitations App Services (PaaS): Cannot be "stopped" fully—only scaled to the lowest tier.
Office 365 / SaaS: Cannot be programmatically stopped—require licensing changes or manual removal.
Stopping the entire Subscription is possible but risky—Azure will mark the subscription as disabled (read-only), and permanent deletion happens in 90 days.
Recommendations If you only want to prevent excessive cost, stopping or deallocating major IaaS resources is usually enough.
For broader coverage, you could:
Tag critical resources and only stop those.
Use Logic Apps or Azure Functions for more complex conditions
References:
https://docs.azure.cn/en-us/cost-management-billing/manage/subscription-states https://docs.azure.cn/en-us/cost-management-billing/manage/subscription-disabled
Please let me know if you face any challenge here, I can help you to resolve this issue further
Provide your valuable Comments.
Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.