hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

updating `azurerm_monitor_diagnostic_setting` fails with `Detected duplicated Log settings` after upgrade to `3.40.0` #20163

Open dvob opened 1 year ago

dvob commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.3.7

AzureRM Provider Version

3.40.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_diagnostic_setting

Terraform Configuration Files

variable "fd_diag_logs" {
  description = "Frontdoor Monitoring Category details for Azure Diagnostic setting"
  type        = list(string)
  default     = ["FrontdoorAccessLog", "FrontdoorWebApplicationFirewallLog"]
}

resource "azurerm_monitor_diagnostic_setting" "fd_diag" {
  name                       = "frontdoor-diag"
  target_resource_id         = azurerm_cdn_frontdoor_profile.main.id
  log_analytics_workspace_id = var.law_id

  dynamic "log" {
    for_each = var.fd_diag_logs
    content {
      category = log.value
      enabled  = true

      retention_policy {
        enabled = false
        days    = 0
      }
    }
  }

  metric {
    category = "AllMetrics"

    retention_policy {
      enabled = false
      days    = 0
    }
  }

  lifecycle {
    ignore_changes = [log, metric]
  }
}

Debug Output/Panic Output

Error: updating Monitor Diagnostics Setting "frontdoor-diag" for Resource "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Cdn/profiles/my-frontdoor-name": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Detected duplicated Log settings 'FrontdoorAccessLog | FrontdoorWebApplicationFirewallLog | FrontDoorHealthProbeLog | FrontDoorAccessLog | FrontDoorWebApplicationFirewallLog'."

Expected Behaviour

No error

Actual Behaviour

After upgrading azurerm from 3.39.1 to 3.40.0 we get the following error during terraform apply:

Error: updating Monitor Diagnostics Setting "frontdoor-diag" for Resource "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my-resource-group/providers/Microsoft.Cdn/profiles/my-frontdoor-name": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Detected duplicated Log settings 'FrontdoorAccessLog | FrontdoorWebApplicationFirewallLog | FrontDoorHealthProbeLog | FrontDoorAccessLog | FrontDoorWebApplicationFirewallLog'."

Now we rolled back to 3.39.1 and the deployment runs without errors.

Steps to Reproduce

No response

Important Factoids

No response

References

Change between 3.39.1 and 3.40.0 in azurerm_monitor_diagnostic_setting: #20048

Other issue regarding these changes: #20140

dvob commented 1 year ago

We updated our resources to use the new enabled_log syntax which fixed the problem for us. So this is no longer an issue for us but probably still a bug since it breaks backwards compatibility with the old syntax.