'Unable to deploy Windows VM: not to be sold in market: 'US'

I'm trying to create a Windows VM in Azure using Terraform. I am getting the error:

The Offer: 'WindowsServer' cannot be purchased by subscription: 'aaaaa-1111-2222-cccc-adf23ad' as it is not to be sold in market: 'US'. Please choose a subscription which is associated with a different market.
  1. Terraform works with CIS L1 & L2 hardened image, so we know TF code is good.
  2. Can successfully deploy WindowsServer to target sub using PowerShell and ARM.
  3. Resource group is uksouth.
  4. All resources are being deployed to uksouth.
  5. Subscription is an Enterprise Agreement. As far as I know, there is no region directly associated with subscriptions.
  6. Deployment uses an SPN.
  7. Deployment is run from Azure DevOps via private agents on containers in uksouth.
  8. license_type is set to Windows_Server. We have tried using retail.
  9. SPN in target AAD was created with a guest account.
  10. Guest account's home AAD is located in United States datacenters.
  11. SPNs AAD is located in EU Model Clause compliant datacenters.

The only link to the US is with my AAD account (guest account) which is located in the US.

I think this is a red herring, but we've accepted the user license agreement using the SPN and a user. We've also deployed VMs using the UI which automagically accepted the agreement.

$Publisher = "MicrosoftWindowsServer"
$Offer = "WindowsServer"
$Sku = "2019-datacenter-gensecond"

Get-AzMarketplaceTerms -Publisher $Publisher -Product $Offer -Name $Sku | Set-AzMarketplaceTerms -Accept

For bots, the full error is:

Error: creating Windows Virtual Machine: (Name "MYSERVER" / Resource Group "WindowsServers"):
compute.VirtualMachinesClient#CreateOrUpdate: Failure sending request:
StatusCode=400 -- Original Error: Code="ResourcePurchaseValidationFailed" 
Message="User failed validation to purchase resources. 
Error message: 'Offer with PublisherId: 'MicrosoftWindowsServer', OfferId: 'WindowsServer' cannot be purchased due to validation errors. For more information see details. Correlation Id: 'a72b1a34-aa3a-6d32-3220-eaac50b32c35' 
The Offer: 'WindowsServer' cannot be purchased by subscription: 'aaaaa-1111-2222-cccc-adf23ad' as it is not to be sold in market: 'US'. Please choose a subscription which is associated with a different market. Correlation Id 'a72b1a34-aa3a-6d32-3220-eaac50b32c35'.'"

If anyone has any ideas, I'd be grateful if you could share.

T. I. A.



Solution 1:[1]

It turned out that the problem was caused by having a plan block.

Solution: Remove the plan block: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_virtual_machine

We had been using the Terraform code to deploy a non-Microsoft image (CIS) and that required the plan block, whereas MicrosoftWindowsServer Publisher does not require a plan block and the fact that we had it in the code caused this error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 woter324