Creating a VM in Azure Portal - Performance & Efficiency
When creating a virtual machine (VM) using Azure CLI, it is important to understand how the time to complete the process changes as you create more VMs.
We want to know how the number of steps and operations grows when adding more VMs.
Analyze the time complexity of the following operation sequence.
# Create a resource group
az group create --name MyResourceGroup --location eastus
# Create a virtual machine
az vm create --resource-group MyResourceGroup --name MyVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
# Repeat VM creation for multiple VMs
for i in range(1, n+1):
az vm create --resource-group MyResourceGroup --name MyVM$i --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
This sequence creates a resource group once, then creates multiple VMs one by one inside that group.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: VM creation API call for each VM.
- How many times: Once for the resource group, then n times for each VM.
Each VM creation requires a separate API call and provisioning process, so the total time grows as you add more VMs.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 1 (resource group) + 10 (VMs) = 11 |
| 100 | 1 + 100 = 101 |
| 1000 | 1 + 1000 = 1001 |
Pattern observation: The number of operations grows directly with the number of VMs created.
Time Complexity: O(n)
This means the time to create VMs grows linearly with the number of VMs you want to create.
[X] Wrong: "Creating multiple VMs at once takes the same time as creating one VM."
[OK] Correct: Each VM requires its own setup and resources, so time adds up with each VM.
Understanding how operations scale helps you plan cloud resources and estimate deployment times in real projects.
"What if we used a VM scale set instead of creating individual VMs? How would the time complexity change?"
Practice
Solution
Step 1: Start VM creation in Azure Portal
When creating a VM, you first open the Azure Portal and start the 'Create a virtual machine' process.Step 2: Enter basic details like name and region
The first required details are the VM's name and the region where it will be hosted.Final Answer:
Choose the VM name and region -> Option AQuick Check:
First step is naming and region selection [OK]
- Trying to connect before VM is created
- Selecting size before naming VM
- Installing software before VM setup
Solution
Step 1: Locate the 'Image' section in VM creation
During VM setup, there is a section called 'Image' where you select the OS image.Step 2: Select a predefined OS image
You pick from available images like Windows Server or Ubuntu Linux before creating the VM.Final Answer:
Select the image during VM setup under 'Image' section -> Option DQuick Check:
Image selection happens during setup [OK]
- Thinking image is chosen after VM is created
- Assuming Azure picks image automatically
- Believing you must upload your own image
Solution
Step 1: Identify the OS type of the VM
The VM is Linux-based, which typically uses SSH for secure command-line access.Step 2: Use SSH to connect
SSH is the standard protocol to connect securely to Linux VMs remotely.Final Answer:
SSH (Secure Shell) -> Option BQuick Check:
Linux VM connection uses SSH [OK]
- Trying to use RDP on Linux VM
- Using FTP or HTTP to connect to VM
- Confusing protocols for connection
Solution
Step 1: Check network security settings
Remote Desktop uses port 3389, which must be allowed in the VM's network security group (NSG).Step 2: Identify blocked port issue
If NSG blocks port 3389, RDP connections fail even if VM is running.Final Answer:
Network security group (NSG) blocks RDP port 3389 -> Option AQuick Check:
Blocked RDP port causes connection failure [OK]
- Assuming VM size affects RDP connection
- Confusing OS image type after creation
- Thinking VM name affects connectivity
Solution
Step 1: Choose secure authentication method
SSH key authentication is more secure than passwords for Linux VMs.Step 2: Open only necessary port in NSG
Opening port 22 for SSH allows secure remote access; avoid opening unnecessary ports.Step 3: Avoid insecure options
Opening RDP port 3389 to all IPs or disabling NSG reduces security.Final Answer:
Use a Linux VM, select SSH key authentication, open port 22 in NSG -> Option CQuick Check:
SSH key + port 22 open = secure access [OK]
- Using password authentication over SSH
- Opening RDP port to all IPs
- Disabling NSG for convenience
Ready to prove it?
Pass the test and this pattern moves unknown
