Last active
September 21, 2018 16:23
-
-
Save DexterPOSH/ee175d96e5a4ce8fe657fe7e8b7c6028 to your computer and use it in GitHub Desktop.
test for a VMSKU deployment does not exceed VM SKU Family & Region Quota
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Describe "VM Sku Quota validation. Region - $Location" -Tag "Azure","Cloud", "Quota" { | |
#TODO - wrap these as helper functions | |
# Credit - Irwin for refactoring the logic below. | |
$vmSKU = Get-AzureRmComputeResourceSku | Where-Object -FilterScript { | |
$PSItem.Locations.Contains($Location) -and | |
$PSitem.ResourceType -eq 'VirtualMachines' -and | |
$PSitem.Name -eq $VMSkuName | |
} | |
$vmResourceUsageQuota = Get-AzureRmVMUsage -Location $Location | |
$vmFamilySKULimit = $vmResourceUsageQuota.Where({$PSitem.Name.value -eq $vmSKU.Family}) | |
$requiredvCPU = $vmSKU.Capabilities.Where({$_.Name -eq 'vCPUs'}).Value | |
$TotalRegionalvCPUsLimit = $VMResourceUsageQuota.Where({$PSitem.Name.value -eq 'Cores'}) | |
Context "Compute Quota validation. Region - $Location" { | |
It "Should not exceed the VM Family SKU limit $($vmFamilySKULimit.Limit)" { | |
$newVCPUcount = $vmFamilySKULimit.CurrentValue + $requiredvCPU | |
$newVCPUcount | | |
Should -BeLessOrEqual $vmFamilySKULimit.Limit -Because "Deploying the VM with $requiredvCPU would exceed the Family SKU limit $($vmFamilySKULimit.Limit)" | |
} | |
It "Should not exceed the Total regional vCPUs limit $($TotalRegionalvCPUsLimit.Limit)" { | |
$newVCPUcount = $TotalRegionalvCPUsLimit.CurrentValue + $requiredvCPU | |
$newVCPUcount | | |
Should -BeLessThan $TotalRegionalvCPUsLimit.Limit -Because "Deploying the VM with $requiredvCPU would exceed the Total cores limit $($TotalRegionalvCPUsLimit.Limit)" | |
} | |
} | |
} |
$Location = 'westus2'
$VMSkuName = 'Standard_D2s_v3'
Describe "VM Sku Quota validation. Region - $Location" -Tag "Azure","Cloud", "Quota" {
#TODO - wrap these as helper functions
$vmSKU = Get-AzureRmComputeResourceSku | Where-Object -FilterScript {
$PSItem.Locations.Contains($Location) -and
$PSitem.ResourceType -eq 'VirtualMachines' -and
$PSitem.Name -eq $VMSkuName
}
$vmResourceUsageQuota = Get-AzureRmVMUsage -Location $Location
$vmFamilySKULimit = $vmResourceUsageQuota.Where({$PSitem.Name.value -eq $vmSKU.Family})
$requiredvCPU = $vmSKU.Capabilities.Where({$_.Name -eq 'vCPUs'}).Value
$TotalRegionalvCPUsLimit = $VMResourceUsageQuota.Where({$PSitem.Name.value -eq 'Cores'})
Context "Compute Quota validation. Region - $Location" {
It "Should not exceed the VM Family SKU limit $($vmFamilySKULimit.Limit)" {
$newVCPUcount = $vmFamilySKULimit.CurrentValue + $requiredvCPU
$newVCPUcount |
Should -BeLessOrEqual $vmFamilySKULimit.Limit -Because "Deploying the VM with $requiredvCPU would exceed the Family SKU limit $($vmFamilySKULimit.Limit)"
}
It "Should not exceed the Total regional vCPUs limit $($TotalRegionalvCPUsLimit.Limit)" {
$newVCPUcount = $TotalRegionalvCPUsLimit.CurrentValue + $requiredvCPU
$newVCPUcount |
Should -BeLessThan $TotalRegionalvCPUsLimit.Limit -Because "Deploying the VM with $requiredvCPU would exceed the Total cores limit $($TotalRegionalvCPUsLimit.Limit)"
}
}
}
@irwins Thanks mate!
I think I did not look into the VMSKU for the family this simplifies the logic 👍
Editing the gist and giving you credits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like it! So I looked into the familySize equation. Turns out some of them are quite funky...
Fun fact: the familysize is a property... ;-)
You can also update gist right?