Post

Azure Hybrid Benefit - Terraform + Automation Account for Windows VM

Azure Hybrid Benefit - Terraform + Automation Account for Windows VM

HCL Azure


What is Azure Hybrid Benefit (AHB)?

Azure Hybrid Benefit is a valuable cost-saving benefit that allows you to leverage your existing on-premises Windows Server and SQL Server licenses with active Software Assurance or subscriptions on Azure. By taking advantage of this benefit, you can save up to 85% compared to standard pay-as-you-go rates and achieve the lowest possible cost of ownership when you combine it with reservations savings and extended security updates. Azure Hybrid Benefit can also be applied to SQL on Azure and Azure Dedicated Host, and it provides dual-use rights for 180 days, enabling you to maintain your on-premises operations while migrating to Azure. Additionally, this benefit now extends to RedHat and SUSE Linux subscriptions, offering even more flexibility.

Moreover, I have automated the conversion to Azure Hybrid Benefit for Windows VM to make the process more streamlined and efficient. For more information on Azure Hybrid Benefit and how it can help you save costs on Azure, please visit: https://azure.microsoft.com/en-us/pricing/hybrid-benefit/


The Terraform code provisions the following Azure resources:

#ResourceFile Name
01Resource Groupr_resource_group.tf
02Automation Accountr_automation_account.tf
03Runbook in Automation Accountr_ahb_runbook.tf
04Script for the Runbookpowershell/ahb_automation.ps1
05Schedule the Runbook in the Automation Accountr_schedule.tf
06Associate the schedule in the runbook within the automation accounta_ahb_schedule.tf
07Role Assignment in Management Groupr_ahb_iam.tf

Inputs

The Terraform code requires the following input parameters:

NameDescriptionTypeStandardRequired
subscription_idsubscription id in which azure resources to be created and billedstringnullYes
locationdefault regionstringnullYes
rg_nameresource group namestringrg-automationNo
aa_nameautomation account namestringaa-finopsNo
ahb_runbook_namerunbook name in automation accountstringahbNo
schedule_nameschedule name in automation accountstringMonthlyNo
mg_idmanagement group id that will be given permission to change the ahb configurationstringnullYes


In Terraform automation, a resource group called “rg-automation” and an automation account called “aa-finops” are created. A runbook with a PowerShell script is created to enable the Azure Hybrid Benefit for all VMs in existing resource groups and subscriptions to which you grant permission.

In this case, the code is for the management group you specify and will run monthly on the last day of each month at 5:00 AM New Zealand time.

NOTE: If you are going to use this code after 30/04/2023, it will be necessary to update the “start_time” parameter in the r_schedule.tf file.


Repository: https://github.com/diegosrp/ahb

This post is licensed under CC BY 4.0 by the author.