Open chintavasisht opened 1 year ago
This needs to be marked/categorized as a bug. Not sure why the bot removed removed the label
Hi @chintavasisht , thanks for submitting this issue. The error message "Failure sending request: StatusCode=409" should be error message returned from Service REST API, indicates that there is a conflict with the current state of the resource. This error can occur if there is an existing diagnostic setting with the same log category as the one you are trying to create. I can reproduce a similar error with below config. Could you please try using different log category for each of the diagnostic setting?
Thanks.
│ Error: creating Monitor Diagnostics Setting "example2" for Resource "/subscriptions/xxx/resourceGroups/wt-example-resources/providers/Microsoft.Sql/servers/example-sqlserverwt/databases/accexample-db-d": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure responding to request: StatusCode=409 -- Original Error: autorest/azure: Service returned an
error. Status=409 Code="Conflict" Message="Data sink '/subscriptions/xxx/resourceGroups/wt-example-resources/providers/Microsoft.EventHub/namespaces/accexample-EHN-1231/authorizationRules/example' is already used in diagnostic setting 'example' for category 'SQLSecurityAuditEvents'. Data sinks can't be reused in different settings on the same category for the same resource."
│
│ with azurerm_monitor_diagnostic_setting.example2,
│ on main.tf line 72, in resource "azurerm_monitor_diagnostic_setting" "example2":
│ 72: resource "azurerm_monitor_diagnostic_setting" "example2" {
│
Hi @teowa, Thanks and I was aware that it was due to a conflict. I verified this a few hours later in the Azure portal and I saw the exact error you posted in the Azure portal and realized what was happening. However, what bums me out is the fact that it does succeed sometimes with the same category. Could you try this out with multiple databases with different SKUs and see how it goes?
Im just wondering, how you in your case the error message returns with full detail of the conflict and for me it returns Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
.
Could it be inconsistency in how the Azure API is handling it?
I was having the same issue,
Error: updating Monitor Diagnostics Setting ... diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
But then I found the root cause:
Data sink *** is already used in diagnostic setting 'eventhub' for category 'ApplicationGatewayAccessLog'. Data sinks can't be reused in different settings on the same category for the same resource.
Thanks @teowa for pointing in the right direction.
I have same problem.
Unable to create new with terraform "azurerm" if azurerm_monitor_diagnostic_setting already exists.
I agree @teowa opinions, but It possible that I create new "azurerm_monitor_diagnostic_setting" having the same log category on Azure Web Portal. So, I guess the phenomenon should be solved.
My code is below↓
resource "azurerm_monitor_diagnostic_setting" "this" {
name = "xxxx-activity-log-to-admin-storage-blob"
target_resource_id = "/subscriptions/${var.subscription_id}"
storage_account_id = "/subscriptions/${var.admin_subscription_id}/resourceGroups/admin-resource-group/providers/Microsoft.Storage/storageAccounts/xxxxxxxxxx"
dynamic "enabled_log" {
for_each = ["Administrative", "Security", "ServiceHealth", "Alert", "Recommendation", "Policy", "Autoscale", "ResourceHealth"]
content {
category = enabled_log.value
retention_policy {
enabled = true
days = 0
}
}
}
}
Error
Error: creating Monitor Diagnostics Setting "xxxx-log-to-admin-storage-blob" for Resource "/subscriptions/xxxxxxxxxx": diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
Is there an existing issue for this?
Community Note
Terraform Version
0.15.5
AzureRM Provider Version
3.49.0
Affected Resource(s)/Data Source(s)
azurerm_monitor_diagnostic_setting
Terraform Configuration Files
Debug Output/Panic Output