Recently Microsoft announced some exciting news in relation to Azure Hybrid Use Benefit (AHB) for SQL Server VMs. If you’re not familiar with Hybrid Benefit, it basically allows customers with appropriate Software Assurance to pay a reduced rate when windows Server or SQL Server are run in Azure. Microsoft boast that Azure is the most cost effective place to run SQL Server, and you can save up to 85% by combining Windows Server and SQL Server licenses that you already own.For more information on Azure Hybrid Benefit, and a calculator that will help estimate savings for eligible customers you can see the following link: https://azure.microsoft.com/en-au/pricing/hybrid-benefit/
For SQL Server the way AHB is applied can be summarised in the following way:
SQL Server Enterprise Edition You are eligible for 1 core of SQL Server Enterprise edition in Azure Virtual Machines for every 1 licence core owned on-premises SQL Server Standard Edition You are eligible for 1 core of SQL Server Standard edition in Azure Virtual Machines for every 1 licence core owned on-premisesThis caused a few issues for customers:
Since the only way to activate the AHB was to use the BYOL images, systems that were already deployed could not take advantage of AHB without having to redeploy using the BYOL images BYOL images were not available on CSP Azure Subscriptions, so CSP customers could not take advantage of AHB. There is no public timeline for when BYOL images will be available on CSP subscriptions You could not switch between AHB and Pay as you Go on-demand. There could be instances where Pay as you Go could work out cheaper where you are not running the systems 24/7 such as Dev/Test workloads What’s new in Azure Hybrid Benefit for SQL Server VMsWith the latest announcement Microsoft are resolving all of those issues, by providing a new way to enable AHB on-demand for existing systems and across all subscription types. AHB can be enabled/disabled with no downtime or impact to the VM. The way they have introduced this is to provide a new Azure Resource Type “ Microsoft.SqlVirtualMachine/SqlVirtualMachine “. According to the documentation, this new resource type links to the existing VM resource and obtains SQL Server configurations from the SQL IaaS Agent. The SqlVirtualMachine resource type has a property that can be used to set the SQL Server license type to either AHUB or PAYG.
Enable Azure Hybrid Benefit for SQL Server VMsThe first step is register the new resource provider type “ Microsoft.SqlVirtualMachine “.
Register-AzureRmResourceProvider -ProviderNamespace Microsoft.SqlVirtualMachineNow that we have registered the resource provider type, lets look at an existing VM and see if there are any properties that automatically get enabled. Looking at resources.azure.com we don’t initially see any additional provider types shown.
Run the following commands to get the SQL VM, and create the required sqlVirtualMachine resource
# Get SQL Server VM $vm = Get-AzureRmVm -ResourceGroupName SQL01 -Name SQL01 # Create an AHUB SqlVm New-AzureRmResource -ResourceName $vm.Name -ResourceGroupName $vm.ResourceGroupName -Location $vm.Location -ResourceType Microsoft.SqlVirtualMachine/sqlVirtualMachines -Properties @{virtualMachineResourceId=$vm.Id;sqlServerLicenseType="AHUB"}This new resource is linked to the VM using the Virtual Machine Resource ID, and the property sqlServerLicenseType is used to define whether it is PAYG or AHUB.
Properties : @{ virtualMachineResourceId=/subscriptions/xxxxxxx-xxxxx-xxxxx-xxxxxx-xxxxxxx/resourceGroups/SQL01/providers/Microsoft.Compute/virtualMachines/sql01 ; provisioningState=Succeeded; sqlImageOffer=SQL2016-WS2016;
sqlServerLicenseType=AHUB; sqlImageSku=Standard}
Run the following command to set it on the VM
# Update SqlVirtualMachine SqlServerLicenseType property $SqlVm = Get-AzureRmResource -ResourceType Microsoft.SqlVirtualMachine/SqlVirtualMachines -ResourceGroupName SQL01 -ResourceName SQL01 $SqlVm.Properties.sqlServerLicenseType="AHUB" $SqlVm | Set-AzureRmResource -ForceYou can easily run the command to change it back to PAYG by setting$SqlVm.Properties.sqlServerLicenseType=”PAYG”