Azure Terraform Error: Error message: ‘You have not accepted the legal terms on this subscription

This blog post will show you how to fix the legal terms notice error message when creating a virtual machine that is from the Azure marketplace.

Full Error Message

The full error message is listed below. The error message is that every image that is a marketplace image has legal terms of use that have to be accepted before using the image, and therefore, you get the error message.

creating Windows Virtual Machine "rg-machine"
 (Resource Group "Win-TF"): compute.VirtualMachinesClient#CreateOrUpdate:
 Failure sending request: StatusCode=0 -- Original Error: Code="ResourcePurchaseValidationFailed"
 Message="User failed validation to purchase resources. Error message: 'You have not accepted the legal terms on this subscription: 
'subscription id' for this plan. Before the subscription can be used, you need to accept the legal terms of the image. To read and accept legal terms, use the Azure CLI commands 
described at https://go.microsoft.com/fwlink/?linkid=2110637 or the PowerShell commands available at https://go.microsoft.com/fwlink/?linkid=862451. Alternatively, deploying via the Azure portal provides a UI experience
for reading and accepting the legal terms. Offer details: publisher='microsoftwindowsserver' offer = 'microsoftserveroperatingsystems-previews', 
sku = 'windows-server-2022', Correlation Id: 

Solution

When it comes to solving the problem, I wish the fix was as simple as adding peace of code to your configuration and re-running it.

The solution requires the usage of a Terraform import command that needs to run before running the configuration.

In my case, I am planning to deploy a Windows Server 2022 image from the marketplace with the following details:

  plan{
    name  = "windows-server-2022"
    publisher ="microsoftwindowsserver"
    product = "microsoftserveroperatingsystems-previews"
  }

Terraform Import

To accept the terms, I need to first run the Terraform import command with the details of the image plan.

Note: You will need your Azure subscription ID for this command to work. You will find it in the error message or in the Azure portal.

terraform import azurerm_marketplace_agreement.microsoftwindowsserver /subscriptions/YOUR-AZURE-SUBSCRIPTION-ID/providers/Microsoft.MarketplaceOrdering/agreements/microsoftwindowsserver/offers/microsoftserveroperatingsystems-previews/plans/windows-server-2022

Go ahead and run the command and move to the next step.

Terraform Marketplace Agreement Resource

After importing and accepting the agreement In the Terraform configuration code, We also need to use the following resource, which will run the imported agreement.

resource "azurerm_marketplace_agreement" "microsoftwindowsserver" {
    publisher ="microsoftwindowsserver"
    offer     = "microsoftserveroperatingsystems-previews"
    plan       = "windows-server-2022"
   }

Make sure all the details are correct and run the code.


Posted

in

by