Azure Microsoft Monitoring Agent failing to provision with Terraform












0














Trying to install the MMA agent as part of a VM deployment using Terraform. I am sure the failure is due to the syntax of the extension I am using but I have had no luck determining what it should be. The agent installs but will not join the Log Analytics workspace. I am storing the workspace ID and the Primary Key in Key Vault and passing them into Terraform at execution time. From the extension logs on the VM, it looks like it is getting the correct workspace ID but I can't tell if it is receiving the key correctly. Below is the Terraform syntax I using:



resource "azurerm_virtual_machine_extension" "lawks-test" {
name = "MMA_${azurerm_virtual_machine.test.name}"
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 = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"

settings = <<SETTINGS
{
"workspaceId": "${data.terraform_remote_state.corerg.on_workspace_id}"
}
SETTINGS

protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey": "${var.on_laws_key}"
}
PROTECTED_SETTINGS


Below is what is shown in one of the extension log files:



11/19/2018 9:43:51 PM +00:00 Managed Service Identity extension (Microsoft.ManagedIdentity.ManagedIdentityExtensionForWindows) not found on this box, automaticManagement will be skipped on this box.
11/19/2018 9:43:51 PM +00:00 HandlerConfig found, default config will be override, CloudType changed to 1
11/19/2018 9:43:51 PM +00:00 GET http://169.254.169.254/metadata/instance?api-version=2017-08-01 with requestId 9a17250a-bfd0-4e4b-b9d3-aa4ceaf9007e
11/19/2018 9:43:52 PM +00:00 azureResourceId from metadata service.
11/19/2018 9:43:52 PM +00:00 automaticManagement not enabled.
11/19/2018 9:43:52 PM +00:00 systemWorkspace provision failed due to AutomaticManagementNotEnabled
11/19/2018 9:43:52 PM +00:00 only configSpecifiedWorkspace available.
11/19/2018 9:43:52 PM +00:00 SettingFile changed, re-apply configuration.
11/19/2018 9:43:52 PM +00:00 Adding workspace /subscriptions/<my_subscription_id>/resourcegroups/resource_group/providers/microsoft.operationalinsights/workspaces/my-workspace.
11/19/2018 9:43:53 PM +00:00 Unknown error during enable command : System.ArgumentException: Value does not fall within the expected range.
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject , String , String , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMAConfigHelper.AddCloudWorkspace(String workspaceId, String workspaceKey, Nullable`1 cloudType)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.EnableProgram.Main(String args)









share|improve this question






















  • you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
    – 4c74356b41
    Nov 20 at 14:33










  • You can check if the agent which used to interact between Azure and the vm works well.
    – Charles Xu
    Nov 21 at 9:48










  • @4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
    – phydeauxman
    Nov 21 at 13:49










  • i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
    – 4c74356b41
    Nov 21 at 14:05










  • @4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
    – phydeauxman
    Nov 22 at 13:35
















0














Trying to install the MMA agent as part of a VM deployment using Terraform. I am sure the failure is due to the syntax of the extension I am using but I have had no luck determining what it should be. The agent installs but will not join the Log Analytics workspace. I am storing the workspace ID and the Primary Key in Key Vault and passing them into Terraform at execution time. From the extension logs on the VM, it looks like it is getting the correct workspace ID but I can't tell if it is receiving the key correctly. Below is the Terraform syntax I using:



resource "azurerm_virtual_machine_extension" "lawks-test" {
name = "MMA_${azurerm_virtual_machine.test.name}"
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 = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"

settings = <<SETTINGS
{
"workspaceId": "${data.terraform_remote_state.corerg.on_workspace_id}"
}
SETTINGS

protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey": "${var.on_laws_key}"
}
PROTECTED_SETTINGS


Below is what is shown in one of the extension log files:



11/19/2018 9:43:51 PM +00:00 Managed Service Identity extension (Microsoft.ManagedIdentity.ManagedIdentityExtensionForWindows) not found on this box, automaticManagement will be skipped on this box.
11/19/2018 9:43:51 PM +00:00 HandlerConfig found, default config will be override, CloudType changed to 1
11/19/2018 9:43:51 PM +00:00 GET http://169.254.169.254/metadata/instance?api-version=2017-08-01 with requestId 9a17250a-bfd0-4e4b-b9d3-aa4ceaf9007e
11/19/2018 9:43:52 PM +00:00 azureResourceId from metadata service.
11/19/2018 9:43:52 PM +00:00 automaticManagement not enabled.
11/19/2018 9:43:52 PM +00:00 systemWorkspace provision failed due to AutomaticManagementNotEnabled
11/19/2018 9:43:52 PM +00:00 only configSpecifiedWorkspace available.
11/19/2018 9:43:52 PM +00:00 SettingFile changed, re-apply configuration.
11/19/2018 9:43:52 PM +00:00 Adding workspace /subscriptions/<my_subscription_id>/resourcegroups/resource_group/providers/microsoft.operationalinsights/workspaces/my-workspace.
11/19/2018 9:43:53 PM +00:00 Unknown error during enable command : System.ArgumentException: Value does not fall within the expected range.
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject , String , String , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMAConfigHelper.AddCloudWorkspace(String workspaceId, String workspaceKey, Nullable`1 cloudType)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.EnableProgram.Main(String args)









share|improve this question






















  • you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
    – 4c74356b41
    Nov 20 at 14:33










  • You can check if the agent which used to interact between Azure and the vm works well.
    – Charles Xu
    Nov 21 at 9:48










  • @4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
    – phydeauxman
    Nov 21 at 13:49










  • i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
    – 4c74356b41
    Nov 21 at 14:05










  • @4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
    – phydeauxman
    Nov 22 at 13:35














0












0








0







Trying to install the MMA agent as part of a VM deployment using Terraform. I am sure the failure is due to the syntax of the extension I am using but I have had no luck determining what it should be. The agent installs but will not join the Log Analytics workspace. I am storing the workspace ID and the Primary Key in Key Vault and passing them into Terraform at execution time. From the extension logs on the VM, it looks like it is getting the correct workspace ID but I can't tell if it is receiving the key correctly. Below is the Terraform syntax I using:



resource "azurerm_virtual_machine_extension" "lawks-test" {
name = "MMA_${azurerm_virtual_machine.test.name}"
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 = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"

settings = <<SETTINGS
{
"workspaceId": "${data.terraform_remote_state.corerg.on_workspace_id}"
}
SETTINGS

protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey": "${var.on_laws_key}"
}
PROTECTED_SETTINGS


Below is what is shown in one of the extension log files:



11/19/2018 9:43:51 PM +00:00 Managed Service Identity extension (Microsoft.ManagedIdentity.ManagedIdentityExtensionForWindows) not found on this box, automaticManagement will be skipped on this box.
11/19/2018 9:43:51 PM +00:00 HandlerConfig found, default config will be override, CloudType changed to 1
11/19/2018 9:43:51 PM +00:00 GET http://169.254.169.254/metadata/instance?api-version=2017-08-01 with requestId 9a17250a-bfd0-4e4b-b9d3-aa4ceaf9007e
11/19/2018 9:43:52 PM +00:00 azureResourceId from metadata service.
11/19/2018 9:43:52 PM +00:00 automaticManagement not enabled.
11/19/2018 9:43:52 PM +00:00 systemWorkspace provision failed due to AutomaticManagementNotEnabled
11/19/2018 9:43:52 PM +00:00 only configSpecifiedWorkspace available.
11/19/2018 9:43:52 PM +00:00 SettingFile changed, re-apply configuration.
11/19/2018 9:43:52 PM +00:00 Adding workspace /subscriptions/<my_subscription_id>/resourcegroups/resource_group/providers/microsoft.operationalinsights/workspaces/my-workspace.
11/19/2018 9:43:53 PM +00:00 Unknown error during enable command : System.ArgumentException: Value does not fall within the expected range.
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject , String , String , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMAConfigHelper.AddCloudWorkspace(String workspaceId, String workspaceKey, Nullable`1 cloudType)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.EnableProgram.Main(String args)









share|improve this question













Trying to install the MMA agent as part of a VM deployment using Terraform. I am sure the failure is due to the syntax of the extension I am using but I have had no luck determining what it should be. The agent installs but will not join the Log Analytics workspace. I am storing the workspace ID and the Primary Key in Key Vault and passing them into Terraform at execution time. From the extension logs on the VM, it looks like it is getting the correct workspace ID but I can't tell if it is receiving the key correctly. Below is the Terraform syntax I using:



resource "azurerm_virtual_machine_extension" "lawks-test" {
name = "MMA_${azurerm_virtual_machine.test.name}"
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 = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"

settings = <<SETTINGS
{
"workspaceId": "${data.terraform_remote_state.corerg.on_workspace_id}"
}
SETTINGS

protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey": "${var.on_laws_key}"
}
PROTECTED_SETTINGS


Below is what is shown in one of the extension log files:



11/19/2018 9:43:51 PM +00:00 Managed Service Identity extension (Microsoft.ManagedIdentity.ManagedIdentityExtensionForWindows) not found on this box, automaticManagement will be skipped on this box.
11/19/2018 9:43:51 PM +00:00 HandlerConfig found, default config will be override, CloudType changed to 1
11/19/2018 9:43:51 PM +00:00 GET http://169.254.169.254/metadata/instance?api-version=2017-08-01 with requestId 9a17250a-bfd0-4e4b-b9d3-aa4ceaf9007e
11/19/2018 9:43:52 PM +00:00 azureResourceId from metadata service.
11/19/2018 9:43:52 PM +00:00 automaticManagement not enabled.
11/19/2018 9:43:52 PM +00:00 systemWorkspace provision failed due to AutomaticManagementNotEnabled
11/19/2018 9:43:52 PM +00:00 only configSpecifiedWorkspace available.
11/19/2018 9:43:52 PM +00:00 SettingFile changed, re-apply configuration.
11/19/2018 9:43:52 PM +00:00 Adding workspace /subscriptions/<my_subscription_id>/resourcegroups/resource_group/providers/microsoft.operationalinsights/workspaces/my-workspace.
11/19/2018 9:43:53 PM +00:00 Unknown error during enable command : System.ArgumentException: Value does not fall within the expected range.
at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , ComObject , String , String , Int32 )
at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.MMAConfigHelper.AddCloudWorkspace(String workspaceId, String workspaceKey, Nullable`1 cloudType)
at Microsoft.EnterpriseCloud.Monitoring.MicrosoftMonitoringAgent.Extension.EnableProgram.Main(String args)






azure terraform terraform-provider-azure






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 14:21









phydeauxman

115110




115110












  • you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
    – 4c74356b41
    Nov 20 at 14:33










  • You can check if the agent which used to interact between Azure and the vm works well.
    – Charles Xu
    Nov 21 at 9:48










  • @4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
    – phydeauxman
    Nov 21 at 13:49










  • i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
    – 4c74356b41
    Nov 21 at 14:05










  • @4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
    – phydeauxman
    Nov 22 at 13:35


















  • you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
    – 4c74356b41
    Nov 20 at 14:33










  • You can check if the agent which used to interact between Azure and the vm works well.
    – Charles Xu
    Nov 21 at 9:48










  • @4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
    – phydeauxman
    Nov 21 at 13:49










  • i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
    – 4c74356b41
    Nov 21 at 14:05










  • @4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
    – phydeauxman
    Nov 22 at 13:35
















you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
– 4c74356b41
Nov 20 at 14:33




you are supposed to pass in strings to those, what are you passing in to them? also, take a look here, looks okay to me medium.com/modern-stack/…, except maybe SETTINGS and PROTECTED_SETTINGS should be at the start of the string exactly (closing ones)
– 4c74356b41
Nov 20 at 14:33












You can check if the agent which used to interact between Azure and the vm works well.
– Charles Xu
Nov 21 at 9:48




You can check if the agent which used to interact between Azure and the vm works well.
– Charles Xu
Nov 21 at 9:48












@4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
– phydeauxman
Nov 21 at 13:49




@4c74356b41 thanks for the link on DSC...has some useful info in it...just not for the problem I am trying to solve. I am passing in strings...you can see in the log file that it is getting my workspace ID that I pass in.
– phydeauxman
Nov 21 at 13:49












i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
– 4c74356b41
Nov 21 at 14:05




i dont see a guid anywhere in the output, so wont be able to tell. format the terraform file properly, to start with
– 4c74356b41
Nov 21 at 14:05












@4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
– phydeauxman
Nov 22 at 13:35




@4c74356b41 I did not understand what you meant in your original comment with regards to the formatting. What is wrong with the formatting I have?
– phydeauxman
Nov 22 at 13:35












2 Answers
2






active

oldest

votes


















0














just tested it, here's a working example:



resource "azurerm_resource_group" "test" {
name = "acctestRG1"
location = "UK West"
}

resource "azurerm_virtual_network" "test" {
name = "acctvn"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
name = "acctsub"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}

resource "azurerm_network_interface" "test" {
name = "acctni"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.test.id}"
private_ip_address_allocation = "dynamic"
}
}

resource "azurerm_virtual_machine" "test" {
name = "acctvm1z"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
network_interface_ids = ["${azurerm_network_interface.test.id}"]
vm_size = "Standard_DS2_v2"

storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter-smalldisk"
version = "latest"
}

storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "hostname1"
admin_username = "testadmin"
admin_password = "Password1234!qwe"
}

os_profile_windows_config {
provision_vm_agent = "true"
}
}

resource "azurerm_virtual_machine_extension" "test" {
name = "omsagent"
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 = "MicrosoftMonitoringAgent"
type_handler_version = "1.0"

settings = <<SETTINGS
{
"workspaceId": "workspaceId"
}
SETTINGS

protected_settings = <<PROTECTED_SETTINGS
{
"workspaceKey": "workspaceKey"
}
PROTECTED_SETTINGS # NOTICE THIS STARTS EXACTLY AT THE START OF THE STRING
}


if that doesnt help, the problem is in how you pass the workspaceKey (so you are missing part of the key, or something like that)






share|improve this answer





























    0














    Thanks for those that replied. I discovered what the issue is by trying to do a manual install. The azurerm_log_analytics_workspace resouce has 2 attributes that relate to ID:



    id - The Log Analytics Workspace ID


    and



    workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace


    I was incorrectly trying to use "id" which is the wrong one. Once I used the "workspace_id" attribute, the install worked fine...with no changes to the formatting of the Terraform code.



    The one thing I have often found lacking about Terraform is the documentation.






    share|improve this answer





















    • you can accept you own answer and can consider upvoting my answer ;)
      – 4c74356b41
      Nov 30 at 16:49













    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395060%2fazure-microsoft-monitoring-agent-failing-to-provision-with-terraform%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    just tested it, here's a working example:



    resource "azurerm_resource_group" "test" {
    name = "acctestRG1"
    location = "UK West"
    }

    resource "azurerm_virtual_network" "test" {
    name = "acctvn"
    address_space = ["10.0.0.0/16"]
    location = "${azurerm_resource_group.test.location}"
    resource_group_name = "${azurerm_resource_group.test.name}"
    }

    resource "azurerm_subnet" "test" {
    name = "acctsub"
    resource_group_name = "${azurerm_resource_group.test.name}"
    virtual_network_name = "${azurerm_virtual_network.test.name}"
    address_prefix = "10.0.2.0/24"
    }

    resource "azurerm_network_interface" "test" {
    name = "acctni"
    location = "${azurerm_resource_group.test.location}"
    resource_group_name = "${azurerm_resource_group.test.name}"

    ip_configuration {
    name = "testconfiguration1"
    subnet_id = "${azurerm_subnet.test.id}"
    private_ip_address_allocation = "dynamic"
    }
    }

    resource "azurerm_virtual_machine" "test" {
    name = "acctvm1z"
    location = "${azurerm_resource_group.test.location}"
    resource_group_name = "${azurerm_resource_group.test.name}"
    network_interface_ids = ["${azurerm_network_interface.test.id}"]
    vm_size = "Standard_DS2_v2"

    storage_image_reference {
    publisher = "MicrosoftWindowsServer"
    offer = "WindowsServer"
    sku = "2016-Datacenter-smalldisk"
    version = "latest"
    }

    storage_os_disk {
    name = "myosdisk1"
    caching = "ReadWrite"
    create_option = "FromImage"
    managed_disk_type = "Standard_LRS"
    }

    os_profile {
    computer_name = "hostname1"
    admin_username = "testadmin"
    admin_password = "Password1234!qwe"
    }

    os_profile_windows_config {
    provision_vm_agent = "true"
    }
    }

    resource "azurerm_virtual_machine_extension" "test" {
    name = "omsagent"
    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 = "MicrosoftMonitoringAgent"
    type_handler_version = "1.0"

    settings = <<SETTINGS
    {
    "workspaceId": "workspaceId"
    }
    SETTINGS

    protected_settings = <<PROTECTED_SETTINGS
    {
    "workspaceKey": "workspaceKey"
    }
    PROTECTED_SETTINGS # NOTICE THIS STARTS EXACTLY AT THE START OF THE STRING
    }


    if that doesnt help, the problem is in how you pass the workspaceKey (so you are missing part of the key, or something like that)






    share|improve this answer


























      0














      just tested it, here's a working example:



      resource "azurerm_resource_group" "test" {
      name = "acctestRG1"
      location = "UK West"
      }

      resource "azurerm_virtual_network" "test" {
      name = "acctvn"
      address_space = ["10.0.0.0/16"]
      location = "${azurerm_resource_group.test.location}"
      resource_group_name = "${azurerm_resource_group.test.name}"
      }

      resource "azurerm_subnet" "test" {
      name = "acctsub"
      resource_group_name = "${azurerm_resource_group.test.name}"
      virtual_network_name = "${azurerm_virtual_network.test.name}"
      address_prefix = "10.0.2.0/24"
      }

      resource "azurerm_network_interface" "test" {
      name = "acctni"
      location = "${azurerm_resource_group.test.location}"
      resource_group_name = "${azurerm_resource_group.test.name}"

      ip_configuration {
      name = "testconfiguration1"
      subnet_id = "${azurerm_subnet.test.id}"
      private_ip_address_allocation = "dynamic"
      }
      }

      resource "azurerm_virtual_machine" "test" {
      name = "acctvm1z"
      location = "${azurerm_resource_group.test.location}"
      resource_group_name = "${azurerm_resource_group.test.name}"
      network_interface_ids = ["${azurerm_network_interface.test.id}"]
      vm_size = "Standard_DS2_v2"

      storage_image_reference {
      publisher = "MicrosoftWindowsServer"
      offer = "WindowsServer"
      sku = "2016-Datacenter-smalldisk"
      version = "latest"
      }

      storage_os_disk {
      name = "myosdisk1"
      caching = "ReadWrite"
      create_option = "FromImage"
      managed_disk_type = "Standard_LRS"
      }

      os_profile {
      computer_name = "hostname1"
      admin_username = "testadmin"
      admin_password = "Password1234!qwe"
      }

      os_profile_windows_config {
      provision_vm_agent = "true"
      }
      }

      resource "azurerm_virtual_machine_extension" "test" {
      name = "omsagent"
      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 = "MicrosoftMonitoringAgent"
      type_handler_version = "1.0"

      settings = <<SETTINGS
      {
      "workspaceId": "workspaceId"
      }
      SETTINGS

      protected_settings = <<PROTECTED_SETTINGS
      {
      "workspaceKey": "workspaceKey"
      }
      PROTECTED_SETTINGS # NOTICE THIS STARTS EXACTLY AT THE START OF THE STRING
      }


      if that doesnt help, the problem is in how you pass the workspaceKey (so you are missing part of the key, or something like that)






      share|improve this answer
























        0












        0








        0






        just tested it, here's a working example:



        resource "azurerm_resource_group" "test" {
        name = "acctestRG1"
        location = "UK West"
        }

        resource "azurerm_virtual_network" "test" {
        name = "acctvn"
        address_space = ["10.0.0.0/16"]
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"
        }

        resource "azurerm_subnet" "test" {
        name = "acctsub"
        resource_group_name = "${azurerm_resource_group.test.name}"
        virtual_network_name = "${azurerm_virtual_network.test.name}"
        address_prefix = "10.0.2.0/24"
        }

        resource "azurerm_network_interface" "test" {
        name = "acctni"
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"

        ip_configuration {
        name = "testconfiguration1"
        subnet_id = "${azurerm_subnet.test.id}"
        private_ip_address_allocation = "dynamic"
        }
        }

        resource "azurerm_virtual_machine" "test" {
        name = "acctvm1z"
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"
        network_interface_ids = ["${azurerm_network_interface.test.id}"]
        vm_size = "Standard_DS2_v2"

        storage_image_reference {
        publisher = "MicrosoftWindowsServer"
        offer = "WindowsServer"
        sku = "2016-Datacenter-smalldisk"
        version = "latest"
        }

        storage_os_disk {
        name = "myosdisk1"
        caching = "ReadWrite"
        create_option = "FromImage"
        managed_disk_type = "Standard_LRS"
        }

        os_profile {
        computer_name = "hostname1"
        admin_username = "testadmin"
        admin_password = "Password1234!qwe"
        }

        os_profile_windows_config {
        provision_vm_agent = "true"
        }
        }

        resource "azurerm_virtual_machine_extension" "test" {
        name = "omsagent"
        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 = "MicrosoftMonitoringAgent"
        type_handler_version = "1.0"

        settings = <<SETTINGS
        {
        "workspaceId": "workspaceId"
        }
        SETTINGS

        protected_settings = <<PROTECTED_SETTINGS
        {
        "workspaceKey": "workspaceKey"
        }
        PROTECTED_SETTINGS # NOTICE THIS STARTS EXACTLY AT THE START OF THE STRING
        }


        if that doesnt help, the problem is in how you pass the workspaceKey (so you are missing part of the key, or something like that)






        share|improve this answer












        just tested it, here's a working example:



        resource "azurerm_resource_group" "test" {
        name = "acctestRG1"
        location = "UK West"
        }

        resource "azurerm_virtual_network" "test" {
        name = "acctvn"
        address_space = ["10.0.0.0/16"]
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"
        }

        resource "azurerm_subnet" "test" {
        name = "acctsub"
        resource_group_name = "${azurerm_resource_group.test.name}"
        virtual_network_name = "${azurerm_virtual_network.test.name}"
        address_prefix = "10.0.2.0/24"
        }

        resource "azurerm_network_interface" "test" {
        name = "acctni"
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"

        ip_configuration {
        name = "testconfiguration1"
        subnet_id = "${azurerm_subnet.test.id}"
        private_ip_address_allocation = "dynamic"
        }
        }

        resource "azurerm_virtual_machine" "test" {
        name = "acctvm1z"
        location = "${azurerm_resource_group.test.location}"
        resource_group_name = "${azurerm_resource_group.test.name}"
        network_interface_ids = ["${azurerm_network_interface.test.id}"]
        vm_size = "Standard_DS2_v2"

        storage_image_reference {
        publisher = "MicrosoftWindowsServer"
        offer = "WindowsServer"
        sku = "2016-Datacenter-smalldisk"
        version = "latest"
        }

        storage_os_disk {
        name = "myosdisk1"
        caching = "ReadWrite"
        create_option = "FromImage"
        managed_disk_type = "Standard_LRS"
        }

        os_profile {
        computer_name = "hostname1"
        admin_username = "testadmin"
        admin_password = "Password1234!qwe"
        }

        os_profile_windows_config {
        provision_vm_agent = "true"
        }
        }

        resource "azurerm_virtual_machine_extension" "test" {
        name = "omsagent"
        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 = "MicrosoftMonitoringAgent"
        type_handler_version = "1.0"

        settings = <<SETTINGS
        {
        "workspaceId": "workspaceId"
        }
        SETTINGS

        protected_settings = <<PROTECTED_SETTINGS
        {
        "workspaceKey": "workspaceKey"
        }
        PROTECTED_SETTINGS # NOTICE THIS STARTS EXACTLY AT THE START OF THE STRING
        }


        if that doesnt help, the problem is in how you pass the workspaceKey (so you are missing part of the key, or something like that)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 14:26









        4c74356b41

        24k32050




        24k32050

























            0














            Thanks for those that replied. I discovered what the issue is by trying to do a manual install. The azurerm_log_analytics_workspace resouce has 2 attributes that relate to ID:



            id - The Log Analytics Workspace ID


            and



            workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace


            I was incorrectly trying to use "id" which is the wrong one. Once I used the "workspace_id" attribute, the install worked fine...with no changes to the formatting of the Terraform code.



            The one thing I have often found lacking about Terraform is the documentation.






            share|improve this answer





















            • you can accept you own answer and can consider upvoting my answer ;)
              – 4c74356b41
              Nov 30 at 16:49


















            0














            Thanks for those that replied. I discovered what the issue is by trying to do a manual install. The azurerm_log_analytics_workspace resouce has 2 attributes that relate to ID:



            id - The Log Analytics Workspace ID


            and



            workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace


            I was incorrectly trying to use "id" which is the wrong one. Once I used the "workspace_id" attribute, the install worked fine...with no changes to the formatting of the Terraform code.



            The one thing I have often found lacking about Terraform is the documentation.






            share|improve this answer





















            • you can accept you own answer and can consider upvoting my answer ;)
              – 4c74356b41
              Nov 30 at 16:49
















            0












            0








            0






            Thanks for those that replied. I discovered what the issue is by trying to do a manual install. The azurerm_log_analytics_workspace resouce has 2 attributes that relate to ID:



            id - The Log Analytics Workspace ID


            and



            workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace


            I was incorrectly trying to use "id" which is the wrong one. Once I used the "workspace_id" attribute, the install worked fine...with no changes to the formatting of the Terraform code.



            The one thing I have often found lacking about Terraform is the documentation.






            share|improve this answer












            Thanks for those that replied. I discovered what the issue is by trying to do a manual install. The azurerm_log_analytics_workspace resouce has 2 attributes that relate to ID:



            id - The Log Analytics Workspace ID


            and



            workspace_id - The Workspace (or Customer) ID for the Log Analytics Workspace


            I was incorrectly trying to use "id" which is the wrong one. Once I used the "workspace_id" attribute, the install worked fine...with no changes to the formatting of the Terraform code.



            The one thing I have often found lacking about Terraform is the documentation.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 15:53









            phydeauxman

            115110




            115110












            • you can accept you own answer and can consider upvoting my answer ;)
              – 4c74356b41
              Nov 30 at 16:49




















            • you can accept you own answer and can consider upvoting my answer ;)
              – 4c74356b41
              Nov 30 at 16:49


















            you can accept you own answer and can consider upvoting my answer ;)
            – 4c74356b41
            Nov 30 at 16:49






            you can accept you own answer and can consider upvoting my answer ;)
            – 4c74356b41
            Nov 30 at 16:49




















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395060%2fazure-microsoft-monitoring-agent-failing-to-provision-with-terraform%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin