Azure PowerShell Terraform

Useful Azure Virtual Machine’s Images for Arm and Terraform Templates

I get stuck when considering which image to use for my virtual machines. Has a new image come out??? What options are available to me now? There are so many to choose from. To use virtual machine images, there are four parts that you need to find to reference them in your code.

  • Publisher: The organization that created the image. Examples: Canonical, MicrosoftWindowsServer
  • Offer: The name of a group of related images created by a publisher. Examples: UbuntuServer, WindowsServer
  • SKU: An instance of an offer, such as a major release of a distribution. Examples: 18.04-LTS, 2019-Datacenter
  • Version: The version number of an image SKU.

The publisher usually has some reference to the company that is providing it. For example, Microsoft uses MicrosoftWindowsServer for one of its publisher names. This is where the popular images for Microsoft Servers are located. Depending on the version of Linux you are after they are under providers such as Canonical, RedHat, SUSE, OpenLogic, credativ, CoreOS, SUSE.

The offer is usually some reference to the operating system. Mircosoft uses WindowsServer whereas RedHat uses RHEL. I’ve listed these along with the other popular OS’s at the end of the commands.

The SKU’s relate to the operating system version. Microsoft, you can probably guess this already, uses 2019-DataCenter to name one of them.
RedHat uses 8.2.
Publishername = MicrosoftWindowsServer and Offer = WindowsServer

First Command

Change the ^mic to whatever you are looking for. The ^ means it starts with, in this case, starts with “mic”

get-azvmimagePublisher -location uksouth | select publishername | ? {$_.publishername -match "^mic"}

Second Command

get-azvmimageoffer -location uksouth -publishername "MicrosoftWindowsServer"

Third Command

get-azvmimagesku -location uksouth -publishername "MicrosoftWindowsServer" -offer "windowsServer"

To focus the SKU, so it returns only 2016, 2019 images. Use something like the command below.

get-azvmimagesku -location uksouth -publishername "MicrosoftWindowsServer" -offer "windowsServer" | ? {$_.skus -notmatch "^2012" -and $_.skus -notmatch "^2008"}

Fourth Command

Ok, so we are almost there. One final piece of the jigsaw is needed the version. In Terraform form you can use “latest”, and it will apply the current version or if you need a specific version then use the command below.

Get-AzVMImage -Location uksouth -PublisherName "MicrosoftWindowsServer" -offer "windowsServer" -Sku 2019-DataCenter | Select Version

Putting the parts together

  • Microsoft – "MicrosoftWindowsServer,WindowsServer,2019-Datacenter"
  • Ubuntu – "Canonical,UbuntuServer,18.04-LTS"
  • RedHat – "RedHat,RHEL,8.2"
  • OpenSUSE-Leap – "SUSE,openSUSE-Leap,15.1"
  • CentOS – "OpenLogic,CentOS,7.6"
  • Debian – "credativ,Debian,9"
  • CoreOS – "CoreOS,CoreOS,Stable"
  • SLES – "SUSE,SLES,12-SP2"

So I hope this helps in understanding what you need to find to select the image you want.

If this helped, please leave a comment below and thanks for reading.