Rana Maninder Singh
Lesson 3 of 8Microsoft Azure for Data & AI

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

ResourceLink
PreviousThe free account
NextStorage
Prerequisitesaz2
Time~50 minutes

What you will learn

By the end of this lesson you will be able to:

  1. Estimate a monthly figure in the pricing calculator before you click Create.
  2. Set a budget and an alert threshold as a percentage of that budget.
  3. Read a spending-limit flag as "card blocked" vs "card live."
  4. Require tags (owner, purpose, stop-after) on every lab resource.
  5. Choose stop vs delete: deallocate a VM vs delete the group.
  6. Compute remaining budget in Python so the rule is testable.

Controls that actually stop money

ControlWhat it doesWhat it does not do
Pricing calculatorA worksheet estimateIt does not cap the subscription
BudgetA named amount you watchCrossing it does not always auto-delete resources
AlertEmail/webhook at a percentIt does not shut the VM down by itself
Spending limitOn some offers, blocks further paid useGone after you upgrade to pay-as-you-go
TagsMetadata so you can find and kill orphansTags do not stop meters
Stop / deleteThe only reliable off switchPortal 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)

  1. 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.
  2. Portal search → Budgets (Cost Management) → pick the subscription → Add. Amount, reset period, alert at 50% and 90%.
  3. Subscription Overview → confirm whether a spending limit is still on.
  4. On create blades, open Tags. Require owner, purpose, stop-after (an ISO date).
  5. 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-budget

Demo 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-group

Guided 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-alert

Independent 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
ok

Common 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-after tag plus a calendar. Treat "Stopped" as incomplete until disks are gone or deallocated.

Snapshot — checked September 2026

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.