I have this terraform script to create two diagnostic setting for different Azure Signal R instances when var.environment == "prod". Kindly note that the Diagnostics setting are two Azure Signal R instances in different Azure regions, using two different Log Analytics workspaces, in two different regions as well.
resource "azurerm_monitor_diagnostic_setting" "Database_diagnostics_SignalR" {
count = var.environment == "prod" ? 2 : 1
name = var.environment != "prod" ? "${var.product}${var.environment}SignalRdiagnostics" : "${var.product}${var.environment}${keys(var.location)[count.index]}SignalRdiagnostics"
target_resource_id = azurerm_signalr_service.product_signalr[count.index].id
log_analytics_workspace_id = var.log_analytics_workspace_ids[count.index]
enabled_log {
category_group = "allLogs"
}
metric {
category = "AllMetrics"
}
}
When I apply the script, I get this error
Error: creating Monitor Diagnostics Setting "xxx-UK1-SignalRdiagnostics" for Resource "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.SignalRService/signalR/xxx-signalr-UK1": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
│
│ with azurerm_monitor_diagnostic_setting.Database_diagnostics_SignalR[0],
│ on tests/signalr_and_pep/signalr_and_pep.tf line 126, in resource "azurerm_monitor_diagnostic_setting" "Database_diagnostics_SignalR":
│ 126: resource "azurerm_monitor_diagnostic_setting" "Database_diagnostics_SignalR" {
│
╵
╷
│ Error: creating Monitor Diagnostics Setting "xxx-UK2-SignalRdiagnostics" for Resource "/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.SignalRService/signalR/xxx-signalr-UK2": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
│
│ with azurerm_monitor_diagnostic_setting.Database_diagnostics_SignalR[1],
│ on tests/signalr_and_pep/signalr_and_pep.tf line 126, in resource "azurerm_monitor_diagnostic_setting" "Database_diagnostics_SignalR":
│ 126: resource "azurerm_monitor_diagnostic_setting" "Database_diagnostics_SignalR" {
I have ensured the Diagnostic setting have different names, and that they target two different Signal R resources in two different regions, and also ensure they use different Log Analytics workspaces, which are solutions proffered by other developers that face similar issue. Yet I keep getting the same error.
You shared a script module that applies these settings to various Azure regions, using different Log Analytics workspaces for each one. This error usually happens when there are Azure resource conflicts, such as when the resource you want to create already exists or has a conflicting configuration.
The error message
StatusCode=409indicates a conflict. This could be due to:**Existing Diagnostic Setting with the Same Name:**You can't have more than one diagnostic setting with the same name for a given target resource in Azure. This applies even across different regions. If your Terraform script generates duplicate names or tries to use a name that already exists, you'll get this error.
Configuration Issues: A possible cause of the problem is that the resources have been set up incorrectly, for example, by using a wrong Log Analytics workspace ID or SignalR service ID.
To address this and meet your requirement, we'll ensure:
var.environmentvalue.Terraform configuration:
terraform.tfvars:Output: