Terraform: Azure VM Availability Set.

Availability Set: It’s logical way of grouping virtual machines together while running the actual Virtual Machines on different piece of hardware or rack so as to say, when you setup VM they are deployed in a rack that’s got power coming in from source, network swithces and perhaps few more things, if anything goes wrong to power source or network switch there’s possibility that you won’t be able to access VM or in worst case the application running on VM would not be accessible.

so to avoid these situation and from redundancy point of view, what we do is spread the web servers as example in to separate fault domain and update domain.

If you aren’t sure what’s fault domain and update domain i would highly encourage you to read about it.

so in case of availability set the underline hardware is spread between two or more racks that’s got multiple source of power or network availability and that’s how if one of your VM goes down the other is still available.

Note Availability set is limited to single data center only, if you are looking for higher redundancy at data center levels then you should look at Availability zones.

we have already seen in some of the earlier post about how to setup Virtual Machine so we will not cover that, we will focus on Availability set and the dependencies on other resources as when you setup a Availability set.

so since you are setting up one or more VMs you would need multiple network interfaces cards, OS Disk drives so you have to factor in the automation for NICs and Disks too.

Network Interface Cards:

See how we have added “Count=2” because we want to setup two network interfaces cards for two virtual machines that we are going to setup, the network interfaces cards needs to named appropriately so that they can be identified in the code down the line, hence we have added. “Count.index“, the first card would be named as “test-web-nic-0” & the other as “test-web-nic-1“, rest is all standard stuff.

Availability Set:

Here we are setting up availability set and the two most important arguments to set is “platform_fault_domain_count” & “platform_update_domain_count“, at a very layman we are spreading our VMs in two different racks, as again if you do not know those terminologies i would highly encourage you to read about it so that conceptually you are clear.

Virtual Machine:

There’s only couple of argument that would change otherwise overall it all remains same.

one of the required argument is “availability_set_id” because we have to let the VM know to which availability set it should be added too, secondly since we are going to have two virtual machines we have added “count=2” and the related “count.index” for network_interface_id and disk name in Storage_os_disk.

You can’t have two VMs using same disk or network interface card hence we use count.index to get the right resource associated with VMs.

Final Result:

Template is available here:Passwords have been removed from terraform.tfvars so please add password.


Leave a Reply

Your email address will not be published. Required fields are marked *