Terraform-provider-azurerm: log_analytics_workspace_id for oms_agent isn't stored in the state

Created on 3 Sep 2020  ·  4Comments  ·  Source: terraform-providers/terraform-provider-azurerm

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

Terraform (and AzureRM Provider) Version

  • Provider Version: 2.25.0
  • I tested it with Terraform 0.12.25, 0.12.29 and 0.13.0

Affected Resource(s)

  • azurerm_log_analytics_workspace
  • azurerm_kubernetes_cluster

Terraform Configuration Files

resource "azurerm_resource_group" "example" {
  name     = "example"
  location = "West Europe"
}

resource "azurerm_kubernetes_cluster" "example" {
  name                = "example"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  dns_prefix          = "example"

  default_node_pool {
    name       = "default"
    node_count = 1
    vm_size    = "Standard_D2_v2"
  }

  identity {
    type = "SystemAssigned"
  }

  addon_profile {
    oms_agent {
      enabled                    = true
      log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
    }

    kube_dashboard {
      enabled = true
    }
  }
}

resource "azurerm_log_analytics_workspace" "example" {
  name                = "example"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  sku                 = "PerGB2018"
  retention_in_days   = 30
}

provider "azurerm" {
  features {}
  version = "2.25.0"
}

Steps to Reproduce

  1. terraform apply
  2. Disable OMS agent:
...
    oms_agent {
      enabled = false
    }
...
  1. terraform apply
  2. Enable OMS agent:
...
    oms_agent {
      enabled                    = true
      log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
    }
...
  1. terraform apply
  2. terraform apply

Expected Behavior

The last terraform apply in step 6 should show no changes.

Actual Behavior

Terraform wants to add the LAW id in step 6.

...
      ~ addon_profile {
          ~ oms_agent {
                enabled                    = true
              + log_analytics_workspace_id = "/subscriptions/***..."
...

Applying the change doesn't help. The same change will be shown on the next plan/apply.

We checked the Azure Portal and API and the LAW is correctly connected.

The terraform state looks like this:

...
                   "enabled": true,
                    "log_analytics_workspace_id": "",
...

We also tried to manually add the id in the state, but the plan still wants to add it again.
Removing and re-importing the azurerm_kubernetes_cluster resource doesn't help either.
After debugging the plan, we confirmed that the Azure API returns the LAW id correctly:

...
"omsagent": {
 "enabled": true,
 "config": {
  "loganalyticsworkspaceresourceid": "/subscriptions/***...."
},
...
bug servickubernetes-cluster upstream-microsoft

Most helpful comment

@muellermatthias Thank you for letting us know this issue!

This is actually an Azure issue, to which I have opened an issue against. In the meanwhile, I opened another PR to side walk this issue in provider. Once it is merged, you should be unblocked :+1:

All 4 comments

@muellermatthias Thank you for letting us know this issue!

This is actually an Azure issue, to which I have opened an issue against. In the meanwhile, I opened another PR to side walk this issue in provider. Once it is merged, you should be unblocked :+1:

Since the fix for this from the Azure Provider's side has been merged in #8374 I'm going to close this issue for the moment - however the upstream bug in the Azure API tracking this is here: https://github.com/Azure/azure-rest-api-specs/issues/10716

This has been released in version 2.28.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.28.0"
}
# ... other configuration ...

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings