15

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.

1
  • 1
    One way is to begin manual deployment of the VM (searching the marketplace for the image you'd like), then export the ARM template to see what the parameters for the image are.
    – cody.codes
    Feb 24, 2022 at 15:20

3 Answers 3

28

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.

7
  • 1
    That worked -- thank you :) You also need to provide the version, the choices for which can be found with az vm image list. Feb 24, 2022 at 16:21
  • I apologize for not including it, but as I said I used this inside packer and there I did not need a version. I should have mentioned that in my original post, but you seemed to figured out so that is nice to hear.
    – Johnny9
    Feb 24, 2022 at 17:13
  • No worries -- thanks for the help, it's most appreciated. I don't know why Microsoft make it so obscure! Feb 24, 2022 at 17:14
  • @Johnny9 Your code works properly in terraform block as well. No need to add packer if not necessary
    – Hussain K
    Mar 15, 2022 at 5:12
  • Thanks for highlighting the CLI usage coming form AWS world, things are quite different in az Oct 2, 2022 at 11:45
14

For anyone else having this issue and having tried the above but still finding it unhelpful. Here is an addition to the above answer:

Login to azure cli and run the following command to list all your existing VMs based on your needs.

az vm image list --all --publisher="Canonical" --sku="20_04-lts-gen2"

You should see an output like this:

{
    "architecture": "x64",
    "offer": "0001-com-ubuntu-server-focal",
    "publisher": "Canonical",
    "sku": "20_04-lts-gen2",
    "urn": "Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:20.04.202209050",
    "version": "20.04.202209050"
},
{
    "architecture": "x64",
    "offer": "0001-com-ubuntu-server-focal",
    "publisher": "Canonical",
    "sku": "20_04-lts-gen2",
    "urn": "Canonical:0001-com-ubuntu-server-focal:20_04-lts-gen2:20.04.202209200",
    "version": "20.04.202209200"
}

In my case, I was having issues with my version. In this case, had to change my code from this ...

source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-focal"
    sku       = "20_04-lts-gen2"
    version   = "latest"
 }

... to this:

source_image_reference {
    publisher = "Canonical"
    offer     = "0001-com-ubuntu-server-focal"
    sku       = "20_04-lts-gen2"
    version   = "20.04.202209200"
 }

As you can see, I used the version based on the output from the az command.

enjoy terraform

0

Code="BadRequest" Message="The selected VM size 'Standard_D2_v2' cannot boot Hypervisor Generation '2'.

When you use ubuntu "20_04-lts-gen2" please select the proper VM size that suits gen2, I'm answering to avoid some confusion. In my case, I used the VM "Standard B2s"

1
  • 2
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 9 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.