Controlling cost: calculator, budgets, alerts, tags, shutdown
Lesson opener
In one line: Estimate before create, tag every resource, alert before the budget is gone, and delete or stop what you are not using.
Why it matters: Cost Management shows yesterday. A Mumbai finance partner wants a cap before the VM ran all weekend.
Before this lesson: The free account.
Before you start
| Resource | Link |
|---|---|
| Previous | The free account |
| Next | Storage |
| Prerequisites | az2 |
| Time | ~50 minutes |
What you will learn
By the end of this lesson you will be able to:
- Estimate a monthly figure in the pricing calculator before you click Create.
- Set a budget and an alert threshold as a percentage of that budget.
- Read a spending-limit flag as "card blocked" vs "card live."
- Require tags (
owner,purpose,stop-after) on every lab resource. - Choose stop vs delete: deallocate a VM vs delete the group.
- Compute remaining budget in Python so the rule is testable.
Controls that actually stop money
| Control | What it does | What it does not do |
|---|---|---|
| Pricing calculator | A worksheet estimate | It does not cap the subscription |
| Budget | A named amount you watch | Crossing it does not always auto-delete resources |
| Alert | Email/webhook at a percent | It does not shut the VM down by itself |
| Spending limit | On some offers, blocks further paid use | Gone after you upgrade to pay-as-you-go |
| Tags | Metadata so you can find and kill orphans | Tags do not stop meters |
| Stop / delete | The only reliable off switch | Portal logout is not an off switch |
WHY Alerts without delete habits are a diary, not a brake.
WHEN Same day as create: calculator screenshot-in-notes (text is enough), budget, tags, calendar stop-after.
Cost. A budget alert does not delete resources. A spending limit on a trial offer can block new paid use; after upgrade that limit is off and the card can be charged. Deallocate a VM to stop compute; disks can still meter until you delete them. Delete resource group is the lab off switch.
Portal click-path (text only)
- Open Pricing calculator from Azure's pricing site (or in-portal estimates on a create blade). Add the product, tier, region, and hours. Save the estimate as a number on the ticket.
- Portal search → Budgets (Cost Management) → pick the subscription → Add. Amount, reset period, alert at 50% and 90%.
- Subscription Overview → confirm whether a spending limit is still on.
- On create blades, open Tags. Require
owner,purpose,stop-after(an ISO date). - Virtual machines → select the VM → Stop (deallocate). Then Disks — delete orphan disks. Or delete the whole resource group.
Demo 1 — Remaining budget and alert state
def budget_state(budget: float, spent: float, warn_at: float = 0.5, stop_at: float = 0.9) -> str:
if budget <= 0:
raise ValueError("budget must be positive")
ratio = spent / budget
if ratio >= 1.0:
return "over-budget"
if ratio >= stop_at:
return "critical-alert"
if ratio >= warn_at:
return "warn-alert"
return "ok"
print(budget_state(100.0, 40.0))
print(budget_state(100.0, 55.0))
print(budget_state(100.0, 92.0))
print(budget_state(100.0, 100.0))
assert budget_state(100.0, 0.0) == "ok"Expected output:
ok
warn-alert
critical-alert
over-budgetDemo 2 — Required tags
REQUIRED = ("owner", "purpose", "stop-after")
def missing_tags(tags: dict) -> list[str]:
return [k for k in REQUIRED if not str(tags.get(k) or "").strip()]
print(missing_tags({"owner": "sam", "purpose": "churn-lab"}))
print(missing_tags({"owner": "sam", "purpose": "churn-lab", "stop-after": "2026-10-01"}))
assert missing_tags({"owner": "sam", "purpose": "x", "stop-after": "2026-10-01"}) == []Expected output:
['stop-after']
[]Demo 3 — Stop vs delete
def off_switch(kind: str) -> str:
if kind == "vm-compute":
return "deallocate-then-check-disks"
if kind == "lab":
return "delete-resource-group"
return "delete-the-resource"
print(off_switch("vm-compute"))
print(off_switch("lab"))
assert off_switch("storage") == "delete-the-resource"Expected output:
deallocate-then-check-disks
delete-resource-groupGuided practice: 80% of a 200 budget
def budget_state(budget: float, spent: float, warn_at: float = 0.5, stop_at: float = 0.9) -> str:
if budget <= 0:
raise ValueError("budget must be positive")
ratio = spent / budget
if ratio >= 1.0:
return "over-budget"
if ratio >= stop_at:
return "critical-alert"
if ratio >= warn_at:
return "warn-alert"
return "ok"
print(budget_state(200.0, 160.0, warn_at=0.5, stop_at=0.8))
assert budget_state(200.0, 160.0, stop_at=0.8) == "critical-alert"Expected output:
critical-alertIndependent practice: refuse untagged create
Deliverable: a function that returns refuse-tags unless all three required tags are present.
REQUIRED = ("owner", "purpose", "stop-after")
def missing_tags(tags: dict) -> list[str]:
return [k for k in REQUIRED if not str(tags.get(k) or "").strip()]
def may_tag_create(tags: dict) -> str:
return "ok" if not missing_tags(tags) else "refuse-tags"
print(may_tag_create({"owner": "riya"}))
print(may_tag_create({"owner": "riya", "purpose": "adf-lab", "stop-after": "2026-10-15"}))
assert may_tag_create({"owner": "riya"}) == "refuse-tags"Expected output:
refuse-tags
okCommon mistake
The deliberate mistake
Symptom: the VM is "Stopped" in the list but Cost analysis still moves.
Diagnosis: stopped (allocated) is not deallocated; or the OS disk is still billing.
Correction: Stop (deallocate), then delete unused disks, or delete the group.
Prevention:
stop-aftertag plus a calendar. Treat "Stopped" as incomplete until disks are gone or deallocated.
Snapshot — checked September 2026
- Azure Pricing calculator is the public estimate worksheet (pricing calculator on Microsoft's Azure pricing pages). It is not a cap.
- Cost Management budgets and alerts are configured per subscription or resource group in the portal. Alerting at a percent does not, by itself, delete resources.
- Trial spending limits are an offer feature; Microsoft's free-account text says you remove that limit when you move to pay-as-you-go.
- Tag names in this lesson (
owner,purpose,stop-after) are a team convention, not a Microsoft-required schema.
Where this connects
What you can now do:
- Estimate, budget, alert, tag, then delete.
- Tell warn vs critical from a spend ratio.
- Distinguish deallocate from delete.
Next lesson: Storage. Blob and Data Lake — still one group, still tagged.