terraform azure OMS VM extension

3.6k views Asked by At

I am trying to add OMS VM extension to a linux machine but its just going for an endless wait during deployment.No errors while running terraform plan. I am using the following piece of code along with VM creation code in terraform.Any clue whats happening here You can find the corresponding powershell and CLI scripts here https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/oms-linux

resource "azurerm_virtual_machine_extension" "test" {
  name                 = "${azurerm_virtual_machine.test.name}/OmsExtension"
  location             = "${azurerm_resource_group.test.location}"
  resource_group_name  = "${azurerm_resource_group.test.name}"
  virtual_machine_name = "${azurerm_virtual_machine.test.name}"
  publisher            = "Microsoft.EnterpriseCloud.Monitoring"
  type                 = "OmsAgentForLinux"
  type_handler_version = "1.4"


  settings = <<SETTINGS
      {
          "workspace ID" : "XXXX",
      }
  SETTINGS

    protected_settings = <<PROTECTED_SETTINGS
      {
          "workspace key" :  "XXXX"
      }
  PROTECTED_SETTINGS
}
1

There are 1 answers

0
Dan W On

At first glance it looks like your Workspace Key and ID "Keys" are not correct, both keys do not appear to have a space in them. Azure should provide a better error like invalid key provided.

I was able to provision successfully using Terraform, it did fail for me a few times but it succeeded with this configuration.

resource "azurerm_virtual_machine_extension" "oms_mma" {
 name                          = "OMSExtension"
 location                      = "${var.vm_location}"
 resource_group_name           = "${var.resource_group_name}"
 virtual_machine_name          = "${var.vm_machine_name}"
 publisher                     = "Microsoft.EnterpriseCloud.Monitoring"
 type                          = "OmsAgentForLinux"
 type_handler_version          = "1.6"
 auto_upgrade_minor_version    = "True"

 settings = <<-BASE_SETTINGS
 {
   "workspaceId" : "myid"
 }
 BASE_SETTINGS

 protected_settings = <<-PROTECTED_SETTINGS
 {
   "workspaceKey" : "mykey"
 }
 PROTECTED_SETTINGS
}