Fourth chapter in the series – Scalable, Highly Available, Secure WordPress on Azure.
This is going to be a short chapter and in here I am going to describe the creation of Availability sets and storage account for our VMS. Availability sets component needs to be created before the VMs because you cannot attach a VM to any avaialbility set after the VMs has been created.
Azure also has a new feature called ‘Proximity Placement Group‘. This feature, although extremely useful, I will not using it in our scenario. Also please bear in mind that, at the time of writing, this feature is in ‘private preview‘ mode and has not GA’ed.
Creation of Availability Sets and Storage
The script to execute to accomplish this task is ‘3-create-availability-set-storage.ps1‘. As is the norm, the complementary script to remove the components created in this chapter is ‘3-remove-availability-set-storage.ps1‘
In the script, I first detect if the Availability set already exists (Azure Cmdlet – Get-AzAvailabilitySet) and if it returns false, create a new Availability set (Azure Cmdlet – New-AzAvailabilitySet ).
$availabilitySet = Get-AzAvailabilitySet `
-ResourceGroupName $RESOURCEGROUP_NAME `
-Name $AvailabilitySetName `
-ErrorAction SilentlyContinue
if (-not $availabilitySet)
{
# imagine that none of the other constructs are created!!!
$availabilitySet = New-AzAvailabilitySet -PlatformUpdateDomainCount 2 `
-PlatformFaultDomainCount 2 `
-ResourceGroupName $RESOURCEGROUP_NAME `
-Name $AvailabilitySetName `
-Location $LOCATION
}
In the second phase of this script, I pre-create the storage required for the front-end VMs in our deployment architecture. I use a function – createStorageAccount – to create the storage account. This function checks for pre-existence of the storage account (using Azure Cmdlet – Get-AzStorageAccount) within a given resource group and if the answer is negative, creates the storage account with ‘Standard_LRS‘ as the SKU using Azure Cmdlet ‘New-AzStorageAccount‘
Function createStorageAccount($storageAccountName)
{
# Lets create the storage account now if it does not exist
$storageAccount = Get-AzStorageAccount `
-ResourceGroupName $RESOURCEGROUP_NAME `
-Name $storageAccountName `
-ErrorAction SilentlyContinue
if (!$storageAccount)
{
# create the storage account
Write-Host "Creating storage account '$storageAccountName'"
$skuName = "Standard_LRS"
$storageAccount = New-AzStorageAccount `
-ResourceGroupName $RESOURCEGROUP_NAME `
-Name $storageAccountName `
-Location $LOCATION `
-SkuName $skuName
}
}
[Validation Tests]: Log on to the Azure portal and manually validate following components have been created
Name | Type |
AvailabilitySet-2 | Availability Set |
blogsstorageaccount | Storage account |
After the execution of previous steps, we’ve created the following components and connections of our final target architecture.