Skip to content
Tutorials Center
My learning

Topics

Lesson 54 of 57 ยท Practice and Review

Practice: Azure Exercises with Solutions

Practice Azure with 15 graded exercises: cost math, CIDR planning, RBAC scope, SLA math, Bicep reading, KQL and choosing services, with worked solutions.

Reading about Azure is not the same as using it. This lesson gives you fifteen exercises that mirror everyday cloud work: estimating a bill, planning address space, reasoning about role assignments, doing availability math, reading and fixing infrastructure code, querying logs and picking the right service. They go from easy to harder, and each one ends with a worked solution.

There is no Azure account behind this page. The exercises that need a calculation or a rule engine come with small runnable stand-ins written in JavaScript or Python: they reproduce the rules (CIDR arithmetic, scope inheritance, SLA formulas) but they are not Azure. All prices are invented round numbers, not current Azure prices. The Bicep and KQL snippets are read-only. Azure's real tools, such as the pricing calculator, are the place to check real numbers.

How to work: try each task before you open the solution. In the runnable examples, the starting answers are deliberately wrong, so you will see FAIL lines first. Edit the values, press Run again and repeat until everything passes.

Part 1: cost and availability math

Exercise 1: the always-on bill

A team runs three identical virtual machines. Assume a pay-as-you-go rate of $0.096 per VM per hour and 730 hours in a month. Each VM has one managed disk costing $9.60 per month. The workload also sends 500 GB of data out to the internet; the first 100 GB are free and the rest costs $0.08 per GB. What is the monthly bill if the VMs run all month? And what is it if they are deallocated outside office hours, so each runs only 360 hours?

Refresher: Virtual Machines and Pricing, Cost Management and Budgets.

Exercise 2: is a reservation worth it?

A one-year reservation for the same VM size gives a 38% discount compared with pay-as-you-go, but you pay for every hour of the term whether the VM runs or not. At what fraction of the month does pay-as-you-go cost the same as the reservation? Is a VM that runs 60% of the time cheaper on reservation or on pay-as-you-go?

Exercise 3: composite SLA (series)

An application depends on an App Service plan (99.95%), an Azure SQL database (99.99%) and a storage account (99.9%). All three must work for the app to work. What composite availability does that give, to three decimals?

Exercise 4: composite SLA (parallel)

The same App Service tier is deployed to two independent regions behind a global load balancer. Treat the two regions as independent. What is the combined availability of the web tier alone, ignoring the load balancer?

Exercise 5: downtime budget

How many minutes of downtime per 30-day month does a 99.9% SLA allow?

Refresher: High Availability, Backup and Disaster Recovery.

Run the checker below. Replace each zero with your answer from pen and paper (or a calculator) and run it again.

JS Exercises 1 to 5: check your math

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Solutions for Part 1

Exercise 1. Always on: compute is 3 x $0.096 x 730 = $210.24, disks are 3 x $9.60 = $28.80, and egress is (500 - 100) x $0.08 = $32.00. The total is $271.04. With 360 hours each, compute drops to 3 x $0.096 x 360 = $103.68, but the disks and the egress do not change, so the bill is $164.48. The lesson: deallocating a VM stops compute charges, yet its disks keep billing, and traffic does not care how long the VM ran.

Exercise 2. A reservation costs 62% of the pay-as-you-go price for a full month, whatever you do. Pay-as-you-go costs 100% times the fraction of hours used. They are equal at a fraction of 0.62. A VM running 60% of the time costs 60% of the full price on demand, which is less than 62%, so pay-as-you-go is (slightly) cheaper: about $42.05 against $43.45 for the same hours. Reservations pay off for steady workloads; for anything stopped often, shutdown schedules or autoscaling save more.

Exercise 3. When every component is required, you multiply the availabilities: 0.9995 x 0.9999 x 0.999 = 0.99840..., so 99.840%. That is lower than the weakest single component, which is always true for series systems. Over a 30-day month, the gap between 99.95% and 99.84% is roughly 48 minutes of extra expected downtime.

Exercise 4. Two independent copies fail together only when both fail. The chance that one is down is 0.0005, so both down is 0.0005 x 0.0005 = 0.00000025. Availability is 99.99998% (99.999975% before rounding to five decimals, which the checker accepts). The independence assumption is the weak point: shared dependencies such as a global control plane, DNS or one deployment pipeline break it, so real-world numbers are lower.

Exercise 5. The allowed downtime is 0.1% of 43,200 minutes, which is 43.2 minutes. For comparison, 99.95% allows 21.6 minutes and 99.99% allows about 4.3 minutes.

Part 2: networking and access

Exercise 6: usable addresses

How many usable IP addresses does a /26 subnet have in Azure?

Exercise 7: plan a VNet

The VNet is 10.20.0.0/16. You need a web subnet for up to 200 hosts, an app subnet for up to 100 hosts, a data subnet for up to 50 hosts, an AzureBastionSubnet (at least a /26) and a GatewaySubnet (at least a /27). Choose non-overlapping ranges inside the VNet. Remember that Azure reserves five addresses in every subnet.

Exercise 8: who can peer?

Four VNets exist: A 10.1.0.0/16, B 10.2.0.0/16, C 10.1.128.0/17 and D 192.168.0.0/24. Which pairs can be peered?

Refresher: Virtual Networks and Subnets.

Python Exercises 6 to 8: address planning

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Exercise 9: read the role assignments

These assignments exist (scopes are shortened):

  • Alice has Reader on subscription s1, and Contributor on resource group rg-web in s1.
  • Bob has Owner on resource group rg-data in s1.

For each statement, say true or false: (a) Alice can delete a VM in rg-web. (b) Alice can delete a VM in rg-data. (c) Alice can read a storage account in rg-data. (d) Alice can assign roles in rg-web. (e) Bob can assign roles in rg-data. (f) Bob can read anything in rg-web. (g) Alice can write in a group named rg-web2.

Exercise 10: least privilege for Carol

Carol must be able to start and restart VMs in rg-web and read everything in rg-web. She must not be able to restart VMs in rg-data, read anything in rg-data, or write storage accounts anywhere. Fix her assignments in the stand-in. The custom role "VM Operator" can read, start, restart and deallocate VMs only.

Refresher: Role-Based Access Control.

JS Exercises 9 and 10: evaluate role assignments

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Solutions for Part 2

Exercise 6. A /26 has 64 addresses. Azure reserves five, so 59 are usable.

Exercise 7. Subnet sizes must cover the hosts plus the five reserved addresses. Web needs 205 addresses, so a /24 (256). App needs 105, so a /25 (128). Data needs 55, so a /26 (64). One valid layout is web 10.20.0.0/24, app 10.20.1.0/25, data 10.20.1.128/26, AzureBastionSubnet 10.20.1.192/26 and GatewaySubnet 10.20.2.0/27. The starting attempt placed the data subnet at 10.20.1.64/26, which sits inside the app /25 (10.20.1.0 to 10.20.1.127), hence the overlap. Many other layouts work; the checker only enforces the rules. Leaving unused ranges (for example the rest of 10.20.2.0/24) is wise.

Exercise 8. Only A and C overlap (10.1.128.0/17 is the upper half of 10.1.0.0/16), so every pair except A-C can be peered: A-B, A-D, B-C, B-D and C-D. Remember that peering is not transitive: A-B and B-C peering does not let A reach C.

Exercise 9. (a) True, Contributor at rg-web allows deletes. (b) False: in rg-data Alice only inherits Reader from the subscription. (c) True, Reader at the subscription covers all read actions below it. (d) False: Contributor excludes the Microsoft.Authorization write actions. (e) True, Owner can manage access. (f) False: Bob's assignment is scoped to rg-data, so nothing grants him anything in rg-web. (g) False: rg-web2 is a different group, not a child of rg-web. The stand-in compares the path with a trailing slash, so a name that merely starts with the same letters does not match, a trap in hand-written scope checks.

Exercise 10. Assign VM Operator at rg-web and Reader at rg-web: replace the single assignment with { principal: "carol", role: "VM Operator", scope: web } and { principal: "carol", role: "Reader", scope: web }. The mistake in the start was granting at subscription scope, which gave restart rights on every VM in the subscription and no read access to storage at all. Assign roles at the narrowest scope that does the job.

Part 3: infrastructure code, logs and service choice

Exercise 11: read the Bicep

BICEP
param env string = 'dev'
param location string = resourceGroup().location

var suffix = uniqueString(resourceGroup().id)

resource st 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'st${env}${suffix}'
  location: location
  kind: 'StorageV2'
  sku: {
    name: env == 'prod' ? 'Standard_GRS' : 'Standard_LRS'
  }
  properties: {
    minimumTlsVersion: 'TLS1_2'
    allowBlobPublicAccess: false
  }
}

output blobEndpoint string = st.properties.primaryEndpoints.blob

Answer: (a) What happens if you deploy with no parameters? (b) What redundancy does prod get? (c) A teammate deploys with env=production. Why might it fail? (A storage account name must be 3 to 24 characters, lowercase letters and digits only, and uniqueString returns 13 characters.)

Refresher: Bicep and ARM Templates.

Exercise 12: find the three problems

BICEP
param sqlPassword string = 'Welcome123!'

resource st 'Microsoft.Storage/storageAccounts@2023-05-01' = {
  name: 'Stg-Data-Prod'
  location: 'westeurope'
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
  }
  properties: {
    allowBlobPublicAccess: true
    supportsHttpsTrafficOnly: false
  }
}

Exercise 13: write a KQL query

A Log Analytics table requests has the columns timestamp, name (the operation), resultCode (a string) and duration (milliseconds). Write a query that finds the three operations with the most server errors (result codes starting with 5) in the last hour.

Exercise 14: read a KQL query

KUSTO
requests
| where timestamp > ago(1h)
| summarize p95 = percentile(duration, 95), n = count() by name
| where n > 10
| order by p95 desc

What does each row contain, and why is the where n > 10 line there?

Refresher: Azure Monitor, Log Analytics and Application Insights.

KQL cannot run here, so this Python stand-in mimics the two queries on a small deterministic table of fake requests. It uses a fixed formula for pseudo-random numbers, so every run produces the same rows.

Python Exercises 13 and 14: KQL-style queries in Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Solutions for Part 3

Exercise 11. (a) With no parameters, env is dev, the location is the resource group's, the name is stdev followed by 13 characters (18 in total), the SKU is Standard_LRS, and the deployment outputs the blob endpoint URL. (b) prod gets Standard_GRS, geo-redundant storage, because of the conditional expression. (c) st + production + 13 characters is 25 characters, one more than the 24-character limit, so the deployment is rejected. A defence is a decorator such as @maxLength(8) on the parameter, or take() to cut the name.

Exercise 12. (1) The password is a plain parameter with a hard-coded default: it should be decorated with @secure(), have no default, and come from a pipeline secret or Key Vault reference. (Here it is unused, which is a second smell.) (2) The storage name has capitals and hyphens, but names allow only lowercase letters and digits, 3 to 24 characters, and must be globally unique, so use something like 'stdataprod${uniqueString(resourceGroup().id)}'. (3) allowBlobPublicAccess: true and supportsHttpsTrafficOnly: false are insecure; set the first to false and the second to true. See also Common Azure Mistakes.

Exercise 13. One valid query:

KUSTO
requests
| where timestamp > ago(1h)
| where resultCode startswith "5"
| summarize errors = count() by name
| top 3 by errors desc

resultCode is a string, so startswith "5" is the right comparison. Filtering on time first keeps the query cheap, because Log Analytics reads less data. The stand-in prints the same three-row shape on its fake table.

Exercise 14. Each row is one operation (name) with its 95th-percentile duration p95 and request count n, sorted slowest first. The where n > 10 line removes operations with too few samples: a percentile from three requests is noise, and one slow call would put a rarely-used operation on top. In the stand-in table, GET /search has 600 ms added on purpose, so it leads the list.

Exercise 15: choose the service

For each scenario pick one: vm, appservice, functions, containerapps or aks.

  1. A timer-driven job runs for three minutes each night and should cost nothing for the other 23 hours and 57 minutes.
  2. A legacy Windows application needs an installer, a registry change and a licensed agent on the operating system.
  3. A containerized HTTP API should scale on request count, even down to zero, with no cluster to manage.
  4. A platform team needs the full Kubernetes API, custom operators and its own networking plugins.
  5. A standard Node.js web app with deployment slots, TLS and a custom domain, with no container knowledge on the team.

Refresher: Choosing a Compute Service.

JS Exercise 15: check your service choices

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Solution. 1 is functions (a timer trigger on a consumption-style plan bills only for execution). 2 is vm, since only a virtual machine gives full control of the operating system. 3 is containerapps (KEDA-based scaling, including zero). 4 is aks, the only option with the complete Kubernetes API. 5 is appservice, a managed platform with slots, TLS and domains built in. If you chose differently, think about the reason: the right answer is the least operational work that meets the requirement.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What happens to the bill for a VM when you deallocate it?

    Deallocation releases the compute, so the hourly VM charge stops. Disks, reserved public IPs and other attached resources keep billing.
  2. 2. A system needs three required components with 99.9%, 99.95% and 99.99% availability. What can you say about the composite availability?

    For components in series you multiply the probabilities, so the result is always lower than the weakest link.
  3. 3. Alice has Contributor on rg-web. Which of these can she do there?

    Contributor can manage resources but cannot manage access. Role assignment needs Owner or User Access Administrator, and her scope is limited to rg-web.
  4. 4. Which Bicep property would you flag in a code review?

    Public blob access should be off unless a container is meant to be public. The other lines are normal or good practice.
  5. 5. Why does a KQL query usually filter on time first?

    Log Analytics partitions data by time, so narrowing the time range early limits what is read. The language does not force it, but it is a core habit.

Summary

  • Deallocated VMs stop compute billing but their disks, and any traffic, keep costing money; a reservation only wins when the workload is steady.
  • Azure reserves five addresses per subnet; connected networks must not overlap; plan with room to grow and special-name subnets in mind.
  • Role assignments inherit downward by scope, Contributor cannot grant access, and the narrowest scope that works is the right one.
  • Series availabilities multiply and are lower than the weakest part; independent copies in parallel improve availability sharply, but only as far as they are truly independent.
  • In Bicep, watch for naming rules, secrets in parameters and insecure property values; in KQL, filter by time first and guard percentiles with a minimum count.
  • Pick the service with the least operational work that meets the requirement.

Next: Common Azure Mistakes and How to Avoid Them.