Search code examples
azureazure-virtual-machineazure-vm-scale-set

ResourcePurchaseValidationFailed when creating a VM via Azure RM REST API


Hi am trying to create a VM using Azure RM REST APIs, but It gives the following error code

"error": {
    "code": "ResourcePurchaseValidationFailed",
    "message": "User failed validation to purchase resources. Error message: 'Offer with PublisherId: Microsoft and OfferId: Windows Server 2008 R2 SP1 not found in Azure Data Market. If this offer has been created recently, please allow upto 30 minutes for this offer to be available for Purchase.'"
  }
}

Has anyone ever faced such kind of problem?

As I understood it is related with PublisherId & OfferId in Azure Data Market. Please help me how can I get this PublisherId & OfferId from Azure Data Market for my subscription.


Solution

  • This could happen if you are including plan information in the request. By adding this, it is forcing the system to purchase something that does not exist. This can be verified by using the below powershell command:

    $pubName = 'MicrosoftWindowsServer'
    $offerName = 'WindowsServer'
    $skuName = '2016-Datacenter'
    $version = '2016.127.20180315'
    
    
    Get-AzureRMVMImage -Location westeurope -Publisher $pubName -Offer $offerName -Skus $skuName -Version $version
    

    As you can see the output shows that plan information are not needed through the PurchasePlan property:

    Id               : /Subscriptions/5e747971-92b4-41ac-963a-188c55951695/Providers/Microsoft.Compute/Locations/westeurope/Publishers/MicrosoftWindowsServer/ArtifactTypes/V
                       MImage/Offers/WindowsServer/Skus/2016-Datacenter/Versions/2016.127.20180315
    Location         : westeurope
    PublisherName    : MicrosoftWindowsServer
    Offer            : WindowsServer
    Skus             : 2016-Datacenter
    Version          : 2016.127.20180315
    FilterExpression :
    Name             : 2016.127.20180315
    OSDiskImage      : {
                         "operatingSystem": "Windows"
                       }
    PurchasePlan     : null
    DataDiskImages   : []
    

    If you are trying to make that script deploy VMs that may or may not need a PurchasePlan alike, you can use the below approach in your script :

    1. Get the latest version number of the image :

      $AzureImageSku = Get-AzureRmVMImage -Location westeurope -PublisherName "MicrosoftWindowsServer" ` -Offer "WindowsServer" -Skus "2016-Datacenter" $AzureImageSku = $AzureImageSku | Sort-Object Version -Descending #put the newest first $AzureImageSku[0] #Newest2016-Datacenter

    2. Check if a plan is needed using Get-AzureRmImage cmdlet

    3. Only if a plan is needed, set the plan information using approach detailed here : https://learn.microsoft.com/en-us/azure/virtual-machines/windows/cli-ps-findimage#deploy-an-image-with-marketplace-terms