Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Right-sizing Azure Virtual Machines
📖 Scenario: You are managing cloud costs for a small company using Azure. You want to analyze the current virtual machines (VMs) and decide which ones can be resized to save money without affecting performance.
🎯 Goal: Build a simple Azure resource configuration that lists VMs with their current sizes and CPU usage, then mark which VMs should be resized based on a CPU usage threshold.
📋 What You'll Learn
Create a dictionary with VM names as keys and their current sizes as values
Add a dictionary with VM CPU usage percentages
Write logic to identify VMs with CPU usage below a threshold (30%)
Add a final dictionary marking VMs recommended for resizing
💡 Why This Matters
🌍 Real World
Cloud administrators often need to analyze VM usage to reduce costs by resizing underused resources.
💼 Career
This project teaches skills useful for cloud cost optimization roles and Azure infrastructure management.
Progress0 / 4 steps
1
Create VM size dictionary
Create a dictionary called vm_sizes with these exact entries: 'vm1': 'Standard_D2s_v3', 'vm2': 'Standard_B1ms', 'vm3': 'Standard_D4s_v3'
Azure
Hint
Use curly braces to create a dictionary with the exact VM names and sizes.
2
Add VM CPU usage dictionary
Create a dictionary called vm_cpu_usage with these exact entries: 'vm1': 25, 'vm2': 55, 'vm3': 15
Azure
Hint
Create a dictionary with VM names as keys and CPU usage as integer values.
3
Set CPU usage threshold and identify low usage VMs
Create a variable called cpu_threshold and set it to 30. Then create a list called low_usage_vms that contains VM names from vm_cpu_usage where the CPU usage is less than cpu_threshold using a list comprehension.
Azure
Hint
Use a list comprehension to filter VMs with CPU usage less than the threshold.
4
Create resize recommendation dictionary
Create a dictionary called resize_recommendations where keys are VM names from vm_sizes and values are true if the VM is in low_usage_vms, otherwise false. Use a dictionary comprehension.
Azure
Hint
Use a dictionary comprehension to assign true or false based on membership in low_usage_vms.
Practice
(1/5)
1. What does right-sizing mean in Azure cloud resource management?
easy
A. Buying the largest possible resources to avoid any performance issues
B. Choosing the best size for your cloud resources to save cost and improve performance
C. Using only free-tier resources regardless of workload needs
D. Deleting unused resources without checking their usage
Solution
Step 1: Understand the term 'right-sizing'
Right-sizing means selecting the most appropriate size of cloud resources based on actual workload needs.
Step 2: Identify the benefits of right-sizing
It helps save money by avoiding over-provisioning and improves performance by matching resources to demand.
Final Answer:
Choosing the best size for your cloud resources to save cost and improve performance -> Option B
Quick Check:
Right-sizing = Best size choice [OK]
Hint: Right-sizing means matching resource size to workload needs [OK]
Common Mistakes:
Thinking bigger is always better
Ignoring cost savings
Confusing right-sizing with deleting resources
2. Which Azure CLI command sequence correctly resizes a virtual machine named myVM to size Standard_DS2_v2?
easy
A. az vm stop --name myVM && az vm resize --name myVM --size Standard_DS2_v2 && az vm start --name myVM
B. az vm resize --name myVM --size Standard_DS2_v2 && az vm stop --name myVM && az vm start --name myVM
C. az vm start --name myVM && az vm resize --name myVM --size Standard_DS2_v2 && az vm stop --name myVM
D. az vm start --name myVM && az vm stop --name myVM && az vm resize --name myVM --size Standard_DS2_v2
Solution
Step 1: Stop the VM before resizing
Azure requires the VM to be stopped before changing its size to avoid errors.
Step 2: Resize and then start the VM
After stopping, resize the VM, then start it again to apply changes.
Final Answer:
az vm stop --name myVM && az vm resize --name myVM --size Standard_DS2_v2 && az vm start --name myVM -> Option A
Quick Check:
Stop, resize, start = correct order [OK]
Hint: Always stop VM before resizing, then start it [OK]
Common Mistakes:
Trying to resize while VM is running
Starting VM before resizing
Wrong command order causing errors
3. Given this Azure CLI snippet, what will be the output status of the VM after execution?
az vm stop --name testVM && az vm resize --name testVM --size Standard_B1s && az vm start --name testVM && az vm show --name testVM --query "powerState" -o tsv
medium
A. VM will be running
B. VM will be stopped
C. VM will be deallocated
D. Command will fail due to wrong order
Solution
Step 1: Analyze command sequence
The VM is stopped, resized, then started, and finally its power state is queried.
Step 2: Determine VM state after commands
Since the VM is started before querying, the power state will show as running.
Final Answer:
VM will be running -> Option A
Quick Check:
Stop, resize, start, then check = running [OK]
Hint: Last command starts VM before checking state [OK]
Common Mistakes:
Assuming VM stays stopped after start command
Confusing deallocated with stopped
Ignoring command order effects
4. You tried to resize an Azure VM using:
az vm resize --name myVM --size Standard_DS3_v2
but got an error. What is the most likely cause?
medium
A. You need to start the VM before resizing
B. The VM name is incorrect
C. The size Standard_DS3_v2 does not exist
D. The VM is currently running and must be stopped before resizing
Solution
Step 1: Understand Azure VM resize requirements
Azure requires the VM to be stopped before resizing to avoid conflicts.
Step 2: Identify common error causes
If the VM is running, resize commands fail with an error prompting to stop the VM first.
Final Answer:
The VM is currently running and must be stopped before resizing -> Option D
Quick Check:
VM must be stopped before resize [OK]
Hint: Stop VM before resizing to avoid errors [OK]
Common Mistakes:
Trying to resize running VM
Assuming VM name typo without checking
Believing VM must be started before resize
5. You have a VM running with size Standard_DS4_v2 but your monitoring shows only 20% CPU usage consistently. Which is the best right-sizing approach to reduce costs without impacting performance?
hard
A. Resize the VM to Standard_DS1_v2 while it is running
B. Keep the current size since resizing may cause downtime
C. Resize the VM to Standard_DS2_v2 after stopping it, then start it again
D. Delete the VM and create a new smaller VM
Solution
Step 1: Analyze CPU usage and sizing
Low CPU usage (20%) suggests the VM is over-provisioned and can be downsized safely.
Step 2: Choose a smaller size and follow correct resize steps
Resizing to Standard_DS2_v2 reduces cost and maintains performance. Stop VM before resizing, then start it.
Final Answer:
Resize the VM to Standard_DS2_v2 after stopping it, then start it again -> Option C
Quick Check:
Stop, resize smaller, start = cost saving [OK]
Hint: Downsize VM after stopping to save cost safely [OK]