# Creating VM's From a Marketplace Image That Needs A Plan

I came across an interesting question today around how to create a VM from a managed image they had created. Initially, I thought this was a relatively simple answer, just click on the image and go to “create VM”, but when they did that they were getting this error:

“Creating a virtual machine from Marketplace image or a custom image sourced from a Marketplace image requires Plan information in the request.”

So not as simple as I thought.

## Requiring A Plan

All VM images in the marketplace have a set of data attached to them around them to define:

• Plan
• Product
• Publisher

If you create a VM from the portal then you probably never see these, but if you use the CLI/PS/ARM etc. then you may have done.

Generally, if you have created an image of a VM, if you then create a VM from this, you don’t have to care about these things. You can create the VM using the wizard in the portal, and off you go. However, this is not the case if the Marketplace image you used has an additional fee, that is paid to the image owner. In this example, they were using the Skylark CentOS 8 Image which has an additional fee over and above the VM cost, which is paid to Skylark. This would apply to any Marketplace image that has a price.

In this scenario, when you use this Marketplace image to either create a VM or to create your own image, which then creates a VM, you must supply the plan, product and publisher details. If you’re not creating the VM from the marketplace (for example you’re using your own image based on this image), then you can’t do this through the portal, so the only way to create a VM from this image is using CLI/PS/ARM. Similarly, if you want to use PowerShell or CLI to create an image using a marketplace image, you need to be able to specify the plan details.

For this article, I’ll use the Skylark image as an example, as this is what the question was about. However, I am in no way endorsing this image. For most use case for CentOS, the aim is not to pay any additional fee for the OS (otherwise you would use Red Hat).

## Creating A VM

To create a VM using an image that is based on a fee-paying Marketplace image, you need to specify these details as part of the create command. However, if you created your original VM and image in the portal, it may not be apparent what these values should be. The easiest way to get these values is to quickly create a VM using the required image using the portal. Once you create this VM, you can go to the “Export Template” menu item. This will show you a generated ARM template for the VM, which includes all the plan information.

"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2019-07-01",
"name": "[parameters('virtualMachines_test1_name')]",
"location": "westeurope",
"plan": {
"name": "centos-8-0",
"product": "centos-8-0",
"publisher": "skylarkcloud"
},


The plan section has the three values we need, name, product and publisher. Once you have these, you can delete the VM if you no longer need them.

Now we have the plan details we can create a new VM using these.

Azure CLI

With the Azure CLI this can all be done in one command:

az vm create --name <name of new VM to create> --location <location> --image <name of image to use> --admin-username <admin username> --admin-password <admin password> --plan-name centos-8-0 --plan-product  --plan-publisher skylarkcloud -g <resource group for new VM>


PowerShell

To do this in PowerShell, you need to create a VM config object, set the plan and then create it.

$vm= New-AzVMConfig -VMName "vmname" -VMSize "Standard_A1" .... additional configuration$vm | Set-AzVMPlan -Name "centos-8-0" -Product "centos-8-0" -Publisher "skylarkcloud"
New-AzVM -VM \$vm .....


Running these commands will create a VM with the right plan. This also works if you have created your own image of a Market Place VM, which again requires the plan information.