azureterraformazure-virtual-machineazure-marketplace

Creating an Azure Linux VM with Ubuntu 20.04 with Terraform


I am trying to create a Linux VM, with Terraform, in the West Europe Azure region, with a Ubuntu Server 20.04 LTS image. I can do this just fine from within the Azure Portal, but Terraform complains that the image doesn't exist:

The platform image 'Canonical:UbuntuServer:20.04-LTS:latest' is not available.

Indeed, az vm image list --location westeurope confirms this; 18.04 LTS exists, but no 20.04 LTS.

I am using the azurerm_linux_virtual_machine resource, with the following source_image_reference:

source_image_reference {
  publisher = "Canonical"
  offer     = "UbuntuServer"
  sku       = "20.04-LTS"  # FIXME SKU doesn't exist in westeurope
  version   = "latest"
}

I'm utterly confused by this! How does one access the images in the Azure Marketplace in Terraform? I've seen suggestions that the plan block is needed, but have no idea (nor have I found any documentation) on how to configure this.


Solution

  • I too was confused at first when I found out that it is available but under a different name, it is indeed kind of hidden.

    offer                 = "0001-com-ubuntu-server-focal"
    publisher             = "Canonical"
    sku                   = "20_04-lts-gen2"
    

    I used this inside packer so I am guessing it is the same in terraform, but you can let me know.