Home > Mobile >  Failure sending request: StatusCode=404 -- Original Error: Code="ArtifactNotFound"
Failure sending request: StatusCode=404 -- Original Error: Code="ArtifactNotFound"

Time:12-10

I'm trying to add AzureMonitor to one of my VM's with terraform, but I'm getting the followin error:

Error: compute.VirtualMachineExtensionsClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="ArtifactNotFound" Message="The VM extension with publisher 'Microsoft.Azure.Monitor' and type 'Microsoft.Compute' could not be found."

Terraform:

resource "azurerm_virtual_machine_extension" "AzureMonitorWindowsAgent" {        
      name                 = "AzureMonitorWindowsAgent"
      publisher            = "Microsoft.Azure.Monitor"
      type                 = "Microsoft.Compute"
      type_handler_version = "1.0"
    
      virtual_machine_id = var.target_vm
}

I have tryed adding this manually and checked out the publiser, type and version like so:

az vm extension list -g MyResourceGroup --vm-name MyVm
{
    "autoUpgradeMinorVersion": true,
    "enableAutomaticUpgrade": null,
    "forceUpdateTag": null,
    "id": "/subscriptions/<guid>/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm/extensions/AzureMonitorWindowsAgent",
    "instanceView": null,
    "location": "uksouth",
    "name": "AzureMonitorWindowsAgent",
    "protectedSettings": null,
    "protectedSettingsFromKeyVault": null,
    "provisioningState": "Succeeded",
    "publisher": "Microsoft.Azure.Monitor",
    "resourceGroup": "rg",
    "settings": null,
    "suppressFailures": null,
    "tags": null,
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "typeHandlerVersion": "1.0",
    "typePropertiesType": "AzureMonitorWindowsAgent"
  }

Whats wrong with my terraform script? fyi I tried Microsoft.Compute/virtualMachines/extensions as well.

CodePudding user response:

Set type = "AzureMonitorWindowsAgent" :

resource "azurerm_virtual_machine_extension" "AzureMonitorWindowsAgent" {        
      name                 = "AzureMonitorWindowsAgent"
      publisher            = "Microsoft.Azure.Monitor"
      type                 = "AzureMonitorWindowsAgent"
      type_handler_version = "1.0"
    
      virtual_machine_id = var.target_vm
}

CodePudding user response:

The attribute in your az vm extension list query shows that the Virtual Machine Extension type should be AzureMonitorWindowsAgent. But the attributes don't map one-to-one between the output of the az vm extension list command and the Terraform arguments. It still requires some translation, thus the type is:

"typePropertiesType": "AzureMonitorWindowsAgent"

As an example, the type key is a VM Extension, but that is the same as the terraform resource itself.

The other issue is that the type_handler_version latest for Windows is currently 1.10. See list of versions.

resource "azurerm_virtual_machine_extension" "AzureMonitorWindowsAgent" {
  name                 = "AzureMonitorWindowsAgent"
  publisher            = "Microsoft.Azure.Monitor"
  type                 = "AzureMonitorWindowsAgent"
  type_handler_version = "1.10"

  virtual_machine_id = var.target_vm
}
  • Related