VMAllocationFailed - VM Allocation Failed: Capacity Constraints
Azure couldn't allocate the VM resources—the selected region or availability zone doesn't have available capacity for your requested VM size. This is a server-side error caused by Azure's temporary capacity constraints (platform-enforced, not user-induced). Capacity varies by region, zone, and VM size, and changes over time due to demand or maintenance. Different zones within a region have independent capacity, so one zone might be full while another has space. Some VM sizes have limited availability. This is transient—retrying later, trying different zones, or using alternative VM sizes often succeeds. Similar allocation failures occur in AKS node allocation and App Service plan allocation.
#Common Causes
- →Regional Capacity Constraint: The selected region doesn't have available capacity for the requested VM size. High demand or maintenance can temporarily exhaust capacity in specific regions. Capacity availability changes over time. This is transient—retrying later or using different zones/sizes may succeed.
- →Availability Zone Capacity Exhaustion: The specific availability zone you selected doesn't have available capacity. Different zones within a region may have different capacity levels. This is transient—trying other zones in the same region may succeed.
- →VM Size Unavailability: The requested VM size isn't available in the selected region or zone. Some VM sizes have limited availability or may be temporarily unavailable due to high demand. This is transient—trying a different VM size or region may succeed.
✓Solutions
- 1Step 1: Diagnose - Try different availability zones within the same region. Availability zones have independent capacity, so one zone may have capacity while another doesn't.
- 2Step 2: Diagnose - List available VM sizes in the region: az vm list-sizes --location <region> --output table
- 3Step 3: Diagnose - Check if the VM size is available: az vm list-sizes --location <region> --query "[?name=='<size>']" --output table
- 4Step 4: Fix - Try zones 1, 2, or 3 if allocation fails in one zone.
- 5Step 5: Fix - Try a different VM size that's available in your region.
- 6Step 6: Fix - Wait 15-30 minutes and retry, or try a different region with better capacity.
- 7Step 7: Fix - Use an availability set for better allocation success rates.
- 8Step 8: Verify - Retry VM creation. It should succeed instead of returning VMAllocationFailed.
</>Code Examples
1# This script helps handle VMAllocationFailed errors by trying different zones and sizes
2
3# Step 1: Set VM creation parameters
4RESOURCE_GROUP="my-resource-group"
5VM_NAME="my-vm"
6REGION="eastus"
7IMAGE="UbuntuLTS"
8DESIRED_SIZE="Standard_D2s_v3"
9echo "Attempting to create VM: $VM_NAME"
10
11# Step 2: List available VM sizes in region
12echo "Listing available VM sizes in region $REGION..."
13az vm list-sizes --location $REGION --query "[].{name:name, numberOfCores:numberOfCores, memoryInMb:memoryInMb}" --output table
14
15# Step 3: Check if desired size is available
16echo "Checking if desired size $DESIRED_SIZE is available..."
17SIZE_AVAILABLE=$(az vm list-sizes --location $REGION --query "[?name=='$DESIRED_SIZE'].name" -o tsv)
18if [ ! -z "$SIZE_AVAILABLE" ]; then
19 echo "Size $DESIRED_SIZE is available"
20else
21 echo "WARNING: Size $DESIRED_SIZE may not be available"
22 echo "Alternative sizes:"
23 az vm list-sizes --location $REGION --query "[?contains(name, 'Standard_D')].name" --output table
24fi
25
26# Step 4: Try different availability zones
27AVAILABILITY_ZONES=("1" "2" "3")
28echo "Trying different availability zones..."
29
30for zone in "${AVAILABILITY_ZONES[@]}"; do
31 echo "Attempting to create VM in zone $zone..."
32
33 if az vm create \
34 --resource-group $RESOURCE_GROUP \
35 --name "${VM_NAME}-zone${zone}" \
36 --image $IMAGE \
37 --size $DESIRED_SIZE \
38 --zone $zone \
39 --generate-ssh-keys \
40 --no-wait 2>&1; then
41 echo "VM creation initiated in zone $zone"
42 break
43 else
44 echo "Failed in zone $zone, trying next..."
45 fi
46done
47
48# Step 5: If all zones fail, try alternative VM sizes
49ALTERNATIVE_SIZES=("Standard_B2s" "Standard_D2s_v2" "Standard_DS2_v2")
50echo "Trying alternative VM sizes..."
51
52for size in "${ALTERNATIVE_SIZES[@]}"; do
53 echo "Attempting to create VM with size $size..."
54
55 if az vm create \
56 --resource-group $RESOURCE_GROUP \
57 --name "${VM_NAME}-${size}" \
58 --image $IMAGE \
59 --size $size \
60 --generate-ssh-keys \
61 --no-wait 2>&1; then
62 echo "VM creation initiated with size $size"
63 break
64 else
65 echo "Failed with size $size, trying next..."
66 fi
67done
68
69# Step 6: Create availability set for better allocation
70echo "Creating availability set for better allocation..."
71az vm availability-set create \
72 --resource-group $RESOURCE_GROUP \
73 --name "myAvailabilitySet" \
74 --platform-fault-domain-count 2 \
75 --platform-update-domain-count 2 \
76 --output table
77
78# Step 7: Instructions for retry strategy
79echo ""
80echo "Allocation retry strategy:"
81echo " 1. Try different availability zones (1, 2, 3)"
82echo " 2. Try alternative VM sizes"
83echo " 3. Wait 15-30 minutes and retry"
84echo " 4. Try a different region"
85echo " 5. Use availability sets for better allocation success"↗Related Errors
Provider Information
This error code is specific to AZURE services. For more information, refer to the official AZURE documentation.