Terraform-provider-azurerm: azurerm_log_analytics_solution - Failure responding to request: StatusCode=404 ... error: invalid character 'S' looking for beginning of value

Created on 15 Aug 2018  路  9Comments  路  Source: terraform-providers/terraform-provider-azurerm

Terraform Version

Terraform v0.11.7

  • provider.azurerm v1.12.0

Affected Resource(s)

azurerm_log_analytics_solution

Terraform Configuration Files

resource "azurerm_resource_group" "monitor_rg" {
  name     = "acctestRG-01"
  location = "NorthEurope"
  provider = "azurerm.default"
}

resource "azurerm_log_analytics_workspace" "acctest_la" {
  name                = "acctest-01"
  sku                 = "Free"
  location            = "westeurope"
  resource_group_name = "${azurerm_resource_group.monitor_rg.name}"
  provider            = "azurerm.default"
}

resource "azurerm_log_analytics_solution" "aks_s" {
  solution_name         = "Containers"
  workspace_resource_id = "${azurerm_log_analytics_workspace.acctest_la.id}"
  workspace_name        = "${azurerm_log_analytics_workspace.acctest_la.name}"
  location              = "westeurope"
  resource_group_name   = "${azurerm_resource_group.monitor_rg.name}"
  provider              = "azurerm.default"

  plan {
    publisher = "Microsoft"
    product   = "OMSGallery/Containers"
  }
}

Debug Output

C:\Temp\aitest> terraform apply --var-file=".\terraform.tfvars"

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:

  • create

Terraform will perform the following actions:

  • azurerm_log_analytics_solution.aks_s
    id:
    location: "westeurope"
    plan.#: "1"
    plan.0.name:
    plan.0.product: "OMSGallery/Containers"
    plan.0.publisher: "Microsoft"
    resource_group_name: "acctestRG-01"
    solution_name: "Containers"
    workspace_name: "acctest-01"
    workspace_resource_id: "${azurerm_log_analytics_workspace.acctest_la.id}"

  • azurerm_log_analytics_workspace.acctest_la
    id:
    location: "westeurope"
    name: "acctest-01"
    portal_url:
    primary_shared_key:
    resource_group_name: "acctestRG-01"
    retention_in_days:
    secondary_shared_key:
    sku: "Free"
    tags.%:
    workspace_id:

  • azurerm_resource_group.monitor_rg
    id:
    location: "northeurope"
    name: "acctestRG-01"
    tags.%:

Plan: 3 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

azurerm_resource_group.monitor_rg: Creating...
location: "" => "northeurope"
name: "" => "acctestRG-01"
tags.%: "" => ""
azurerm_resource_group.monitor_rg: Creation complete after 0s (ID: /subscriptions/<...>/resourceGroups/acctestRG-01)
azurerm_log_analytics_workspace.acctest_la: Creating...
location: "" => "westeurope"
name: "" => "acctest-01"
portal_url: "" => ""
primary_shared_key: "" => ""
resource_group_name: "" => "acctestRG-01"
retention_in_days: "" => ""
secondary_shared_key: "" => ""
sku: "" => "Free"
tags.%: "" => ""
workspace_id: "" => ""
azurerm_log_analytics_workspace.acctest_la: Still creating... (10s elapsed)
azurerm_log_analytics_workspace.acctest_la: Still creating... (20s elapsed)
azurerm_log_analytics_workspace.acctest_la: Still creating... (30s elapsed)
azurerm_log_analytics_workspace.acctest_la: Still creating... (40s elapsed)
azurerm_log_analytics_workspace.acctest_la: Still creating... (50s elapsed)
azurerm_log_analytics_workspace.acctest_la: Still creating... (1m0s elapsed)
azurerm_log_analytics_workspace.acctest_la: Creation complete after 1m5s (ID: /subscriptions/<...>-...rationalinsights/workspaces/acctest-01)
azurerm_log_analytics_solution.aks_s: Creating...
location: "" => "westeurope"
plan.#: "" => "1"
plan.0.name: "" => ""
plan.0.product: "" => "OMSGallery/Containers"
plan.0.publisher: "" => "Microsoft"
resource_group_name: "" => "acctestRG-01"
solution_name: "" => "Containers"
workspace_name: "" => "acctest-01"
workspace_resource_id: "" => "/subscriptions/<...>/resourcegroups/acctestrg-01/providers/microsoft.operationalinsights/workspaces/acctest-01"

Error: Error applying plan:

1 error(s) occurred:

  • azurerm_log_analytics_solution.aks_s: 1 error(s) occurred:

  • azurerm_log_analytics_solution.aks_s: Error retrieving Log Analytics Solution "Containers(acctest-01)" (Resource Group "acctestRG-01"): operationsmanagement.SolutionsClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: error response cannot be parsed: "Solution Not Found : solutionType Containers, workspace acctest-01" error: invalid character 'S' looking for beginning of value

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Expected Behavior

Solution should be assigned to existing log-analytics account

Actual Behavior

Solution deployment fails

Steps to Reproduce

run provided configuration

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
bug servicoms upstream-microsoft

Most helpful comment

What solved the issue for me was setting solution_name to match the plan.product, which in my case was just ContainerInsights. I figured out the solution by enabling the debug log and inspecting raw API responses, so better error messages would be nice, indeed

All 9 comments

Terraform v0.11.11
+ provider.azurerm v1.21.0

Ours is a different error character "W" and is Error creating/updating instead of Error retrieving

* azurerm_log_analytics_solution.akslaw: 1 error(s) occurred:

* azurerm_log_analytics_solution.akslaw: Error creating/updating Log Analytics Solution 
"ContainerInsights(prduse-xxx-law)" 
(Workspace "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-0eb53147bb93/resourcegroups/prduse-xxx-la-rg/providers/microsoft.operationalinsights/workspaces/prduse-xxx-law" 
/ Resource Group "prduse2xxxxxrg"): pollingTrackerBase#updateRawBody: 
failed to unmarshal response body: 
StatusCode=0 -- Original Error: invalid character 'W' looking for beginning of value
Terraform v0.11.11
+ provider.azurerm v1.21.0

Ours is a different error character "W" and is Error creating/updating instead of Error retrieving

* azurerm_log_analytics_solution.akslaw: 1 error(s) occurred:

* azurerm_log_analytics_solution.akslaw: Error creating/updating Log Analytics Solution 
"ContainerInsights(prduse-xxx-law)" 
(Workspace "/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-0eb53147bb93/resourcegroups/prduse-xxx-la-rg/providers/microsoft.operationalinsights/workspaces/prduse-xxx-law" 
/ Resource Group "prduse2xxxxxrg"): pollingTrackerBase#updateRawBody: 
failed to unmarshal response body: 
StatusCode=0 -- Original Error: invalid character 'W' looking for beginning of value

I tried again with the resource group matching the workspace resource group and it succeeded. Perhaps we could use some better error messages? Or we are not parsing them correctly...

Seeing the same error as dcfsc, on the same versions. Having the same resource name on the workspace and the solution don't help.

What solved the issue for me was setting solution_name to match the plan.product, which in my case was just ContainerInsights. I figured out the solution by enabling the debug log and inspecting raw API responses, so better error messages would be nice, indeed

Same issue as @dcfsc . Running Terraform v0.12.12 and provider.azurerm v1.36.1.

In our instance, our Log Analytics workspace is not in the same RG as the rest of the infrastructure, so we're using an aliased azurerm provider, 'azurerm.log'. Here is the script:

data "azurerm_log_analytics_workspace" "log_analytics" {
  provider            = "azurerm.log"
  name                = var.log_analytics_name
  resource_group_name = "RG_Core_Infrastructure"
}


/* Create Azure SQL Analytics solution */

// Azure SQL Analytics
resource "azurerm_log_analytics_solution" "azure_sql_analytics" {
  provider            = "azurerm.log"
  location            = data.azurerm_log_analytics_workspace.log_analytics.location
  resource_group_name = data.azurerm_log_analytics_workspace.log_analytics.resource_group_name
  plan {
    product           = "OMSGallery/AzureSQLAnalytics"
    publisher         = "Microsoft"
  }
  solution_name         = "AzureSQLAnalytics"
  workspace_name        = data.azurerm_log_analytics_workspace.log_analytics.name
  workspace_resource_id = data.azurerm_log_analytics_workspace.log_analytics.workspace_id
}

Here is the Plan:

Terraform will perform the following actions:

  # azurerm_log_analytics_solution.azure_sql_analytics[0] will be created
  + resource "azurerm_log_analytics_solution" "azure_sql_analytics" {
      + id                    = (known after apply)
      + location              = "uksouth"
      + resource_group_name   = "rg_core_infrastructure"
      + solution_name         = "AzureSQLAnalytics"
      + workspace_name        = "nonprod-loganalyrics"
      + workspace_resource_id = "xxxxxxx-a6c6-47a0-9c83-a863acfdf132"

      + plan {
          + name      = (known after apply)
          + product   = "OMSGallery/AzureSQLAnalytics"
          + publisher = "Microsoft"
        }
    }

Here is the result of Apply:

2019-10-31T14:07:38.7164714Z Error: Error creating/updating Log Analytics Solution "AzureSQLAnalytics(nonprod-loganalyrics)" (Workspace "xxxxxxx-a6c6-47a0-9c83-a863acfdf132" / Resource Group "rg_core_infrastructure"): pollingTrackerBase#updateRawBody: failed to unmarshal response body: StatusCode=0 -- Original Error: invalid character 'W' looking for beginning of value
2019-10-31T14:07:38.7164934Z 
2019-10-31T14:07:38.7166167Z   on main.tf line 51, in resource "azurerm_log_analytics_solution" "azure_sql_analytics":
2019-10-31T14:07:38.7167992Z   51: resource "azurerm_log_analytics_solution" "azure_sql_analytics" {

In our case the character is 'F':

Error: Error creating/updating Log Analytics Solution (Workspace "/subscriptions/xxxxxxxxx/resourcegroups/xxxxx/providers/microsoft.operationalinsights/workspaces/security-xxxxxxx" / Resource Group "c7n-aks"): pollingTrackerBase#updateRawBody: failed to unmarshal response body: StatusCode=0 -- Original Error: invalid character 'F' looking for beginning of value

what worked for us is just using:

solution_name = "ContainerInsights

In our case the character is 'F':

Error: Error creating/updating Log Analytics Solution (Workspace "/subscriptions/xxxxxxxxx/resourcegroups/xxxxx/providers/microsoft.operationalinsights/workspaces/security-xxxxxxx" / Resource Group "c7n-aks"): pollingTrackerBase#updateRawBody: failed to unmarshal response body: StatusCode=0 -- Original Error: invalid character 'F' looking for beginning of value

what worked for us is just using:

solution_name = "ContainerInsights

Changing the name to "ContainerInsights` worked for us as well. Debugging terraform you can see that with other names you get a 400 bad request error for the underlying API
The reason for this seems to be the name passed to the API adds the name of workspace to it like so -
test1233ContainerInsights(test1233-workspace-**)

Seems like an issue with the API and a good error message will really help.

API in question is - https://management.azure.com/subscriptions//resourcegroups//providers/Microsoft.OperationsManagement/solutions/**?api-version=2015-11-01-preview

Seems LogAnalytics.Solutions API failed to unmarshal response body when it failed to create solution so that the error message is not helpful. So raised an issue on Azure/azure-rest-api-specs#9672

perhaps a related issue. I got this error...then re-applied and was good..

Error: Error retrieving Log Analytics Solution "ADReplication(la-operations-vjhywhmlbmndfroveecsjfkilkkkwswrkoyyggulnwpcaxdni)" (Resource Group "rg-operations-wtimbuguxbymiqeqyngmpxudjxquvpqejjji"): operationsmanagement.SolutionsClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: error response cannot be parsed: "\"Solution Not Found : solutionType ADReplication, workspace la-operations-vjhywhmlbmndfroveecsjfkilkkkwswrkoyyggulnwpcaxdni\"" error: json: cannot unmarshal string into Go value of type azure.RequestError
Was this page helpful?
0 / 5 - 0 ratings