Some ARM templates require to accept legal terms before they can be deployed. You can find multiple of these templates within the Azure Resource Manager QuickStart Templates which are available on GitHub. This article will show you how to accept these terms using PowerShell.
Prerequisites
Deploy without accepting the terms
We will use the Couchbase Enterprise ARM Template from the QuickStart Templates to show how this can be done. Let’s start with creating an empty resource group for our deployment:
Add-AzAccount # Interactive log in to Azure New-AzResourceGroup 'couchbase' -Location 'West Europe'
We can verify that the resource group is successfully created using the Get-AzResourceGroup cmdlet:
Get-AzResourceGroup $resourceGroupName
Now let’s try to deploy the Couchbase template using the New-AzResourceGroupDeployment cmdlet. Note that we define all necessary parameters for the cmdlet inside the $parameter
variable and pass them using a technique called splatting:
$parameter = @{ TemplateUri = 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/couchbase/azuredeploy.json' TemplateParameterUri = 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/couchbase/azuredeploy.parameters.json' ResourceGroupName = 'couchbase' } New-AzResourceGroupDeployment @parameter
If we run the above code, our deployment will fail with the following error:
New-AzResourceGroupDeployment : 12:39:43 - Error: Code=MarketplacePurchaseEligibilityFailed; Message=Marketplace purchase eligibilty
check returned errors. See inner errors for details.
....
New-AzResourceGroupDeployment : 12:39:43 - Error: Code=BadRequest; Message=Offer with PublisherId: couchbase, OfferId:
couchbase-server-enterprise cannot be purchased due to validation errors. See details for more information.[{"Legal terms have not
been accepted for this item on this subscription: 'a3d8a5c7-b250-4471-828e-5c5bd3d9ff7b'. To accept legal terms using PowerShell,
please use Get-AzureRmMarketplaceTerms and Set-AzureRmMarketplaceTerms API(https://go.microsoft.com/fwlink/?linkid=862451) or deploy
via the Azure portal to accept the terms":"StoreApi"},{"Unsupported Payment instrument, it's neither credit card nor
invoice.":"StoreApi"}]
As expected, the deployment fails because we have not accepted the legal terms yet. The error message also recommends using the Set-AzureRmMarketplaceTerms cmdlet to accept them. Note: The Set-AzureRmMarketplaceTerms
cmdlet is part of the old AzureRM PowerShell module, we will use the new Set-AzMarketplaceTerms cmdlet instead.
Retrieve the agreement terms
To get the legal terms for our deployment we have to take a look at the plan section inside the ARM template:
"plan": { "publisher": "couchbase", "product": "couchbase-server-enterprise", "name": "hourly_pricing" }
We need exactly these three parameters to retrieve the legal terms using the Get-AzMarketplaceTerms cmdlet:
Get-AzMarketplaceTerms ` -Publisher 'couchbase' ` -Product 'couchbase-server-enterprise' ` -Name 'hourly_pricing'
This is how the output looks like:
Publisher : couchbase Product : couchbase-server-enterprise Plan : hourly_pricing LicenseTextLink : https://storelegalterms.blob.core.windows.net/legalterms/3E5ED_legalterms_COUCHBASE%253a24COUCHBASE%253a2DSERVER%25 3a2DENTERPRISE%253a24HOURLY%253a5FPRICING%253a24FDVP3HBDTJF32XNQT5CQGQYBMCCHKOAM3FKBKMDLXWAC264JUSLSLLHLMUNYHGG4O7E AFLSF65RC75TVVPJCBLGBBWSAJMZBMMBIEPY.txt PrivacyPolicyLink : https://www.couchbase.com/privacy-policy Signature : J46OMNBRU4PBFE2T5HYIL5ENKPRQEQMN5L6R4UQ4IXHDIXBHQM2CTVDA6ZI2OVJGWT6UUCHP4SDINYM66IYA5JLSBSQ4KKNCZ3YR3ZI Accepted : False Signdate : 28/05/2019 12:10:48
As you can see in line 9, the legal terms have not been accepted yet. To accept them, simple pipe the previous command to the Set-AzMarketplaceTerms cmdlet and specify the -Accept switch:
Get-AzMarketplaceTerms ` -Publisher 'couchbase' ` -Product 'couchbase-server-enterprise' ` -Name 'hourly_pricing' | Set-AzMarketplaceTerms -Accept
The command will now output the accepted legal terms:
Publisher : couchbase Product : couchbase-server-enterprise Plan : hourly_pricing LicenseTextLink : https://storelegalterms.blob.core.windows.net/legalterms/3E5ED_legalterms_COUCHBASE%253a24COUCHBASE%253a2DSERVER%25 3a2DENTERPRISE%253a24HOURLY%253a5FPRICING%253a24FDVP3HBDTJF32XNQT5CQGQYBMCCHKOAM3FKBKMDLXWAC264JUSLSLLHLMUNYHGG4O7E AFLSF65RC75TVVPJCBLGBBWSAJMZBMMBIEPY.txt PrivacyPolicyLink : https://www.couchbase.com/privacy-policy Signature : 3BRX5QIQCYWDWZSE4V3IRJKNV4HWQHG3Z7DE2YTZT7SLXTTXICSOL3QUZKV6LC6ILAYG6FETKHWX4TEBUMQITXIV56L7OCTMQVBH66Y Accepted : True Signdate : 28/05/2019 12:18:18
That’s it. The Couchbase example template contains two legal terms. If you repeat the process for the second legal terms, the deployment will succeed.