Lab: Mastering Azure Cost Management & Governance
Describe cost management in Azure
Lab: Mastering Azure Cost Management & Governance
In this lab, you will explore the primary tools used to manage and predict cloud spend within Microsoft Azure. You will practice organizing resources with tags, creating a cost budget, and understanding how different factors influence your monthly bill.
[!WARNING] Remember to run the teardown commands at the end of this lab to avoid ongoing charges for any resources provisioned.
Prerequisites
- An active Azure Subscription (Free Trial, Pay-As-You-Go, or Student).
- Azure CLI installed locally or access to the Azure Cloud Shell.
- Permission to create Resource Groups and assign Tags (Owner or Contributor role).
Learning Objectives
- Apply metadata to resources using Azure Tags for cost allocation.
- Navigate the Azure Cost Management + Billing interface.
- Create a Budget with automated alerts to prevent overspending.
- Differentiate between the Pricing Calculator and the Total Cost of Ownership (TCO) Calculator.
Architecture Overview
The following diagram illustrates the relationship between resource organization (tags) and the management layer that tracks these costs.
Step-by-Step Instructions
Step 1: Create a Resource Group with Cost Tags
Tags are name-value pairs that help you categorize resources for billing. Without tags, it is difficult to determine which department or project is responsible for a specific cost.
az group create --name brainybee-cost-lab --location eastus --tags Department=Education Project=AZ900Lab▶Console Alternative
- Search for Resource groups in the Azure Portal.
- Click + Create.
- Enter
brainybee-cost-labas the name. - Navigate to the Tags tab.
- Enter Name:
Department, Value:Education. Enter Name:Project, Value:AZ900Lab. - Click Review + create and then Create.
Step 2: Create a Consumption Budget
A budget allows you to set a soft limit on your spending and receive notifications when you reach specific percentages (e.g., 50%, 80%, or 100%) of that limit.
az consumption budget create --amount 10 --budget-name "MonthlyLabBudget" --category "Cost" --time-grain "Monthly" --start-date "2023-10-01" --end-date "2025-10-01" --contact-emails "<YOUR_EMAIL>"[!TIP] In a real-world scenario, ensure the start date is the first day of the current month.
▶Console Alternative
- Search for Cost Management + Billing.
- Click Cost Management on the left menu.
- Select Budgets and click + Add.
- Set the name to
MonthlyLabBudgetand the amount to10(or your local currency equivalent). - Set up an alert at 80% to notify your email address.
Step 3: Explore the Pricing Calculator
Unlike Cost Management (which tracks actual spend), the Pricing Calculator is used to estimate costs before you deploy any resources.
- Navigate to the Azure Pricing Calculator.
- Add a "Virtual Machine" to your estimate.
- Change the Region and observe how the price fluctuates.
- Change the Operating System from Linux to Windows and note the licensing cost increase.
Visualizing the Hierarchy
Cost management is applied across the Azure hierarchy. The higher the level, the more aggregated the cost data becomes.
\begin{center} \begin{tikzpicture}[node distance=1.2cm, every node/.style={draw, rectangle, rounded corners, minimum width=4cm, fill=blue!5, font=\small}] \node (MG) {Management Groups (Policy & Governance)}; \node (SUB) [below of=MG] {Subscriptions (Billing Boundary)}; \node (RG) [below of=SUB] {Resource Groups (Lifecycle Boundary)}; \node (RES) [below of=RG] {Resources (The Cost Drivers)};
\draw[->, thick] (MG) -- (SUB); \draw[->, thick] (SUB) -- (RG); \draw[->, thick] (RG) -- (RES); \end{tikzpicture} \end{center}
Checkpoints
| Verification Task | Expected Result |
|---|---|
Run az group show -n brainybee-cost-lab | Output should show the Department: Education tag. |
| Check the Budgets blade in Portal | MonthlyLabBudget should appear in the list. |
| Compare TCO vs. Pricing Calculator | TCO is for migration (on-prem vs cloud); Pricing is for new cloud estimates. |
Troubleshooting
| Issue | Possible Cause | Fix |
|---|---|---|
| "Subscription not found" | CLI is logged into the wrong tenant. | Run az login or az account set --subscription <ID>. |
| Budget creation fails | Some "Free Trial" or "Sponsorship" accounts have restricted API access for budgets. | Use the Azure Portal UI to create the budget manually. |
| Tags not appearing in billing | There is a 24-48 hour delay for tags to populate in Cost Analysis. | Wait for the next billing cycle or check the resource directly. |
Clean-Up / Teardown
To ensure you are not charged for any accidental resources created during this session, delete the resource group. This will delete all resources within it.
az group delete --name brainybee-cost-lab --yes --no-wait[!IMPORTANT] The
--no-waitflag allows the command to return immediately while Azure processes the deletion in the background.
Cost Estimate
- Azure Cost Management: Free (standard features).
- Resource Group / Tags: Free.
- Budget Alerts: Free (standard tier).
- Total Lab Cost: $0.00 (Assuming no expensive resources like high-tier VMs were deployed).