Open vscoding1988 opened 1 year ago
We have seem the same issue as well. In order to associate the DCR rule to a Log Analytics Workspace, we need to use:
However, this becomes a race condition. We were able to work around this by deploying the LAW block without the DCR association. Then we deploy the DCR rule. Then we update the LAW block with the DCR collection rule ID association.
It would be much better to associate the DCR to the LAW within the same block. This would avoid the race condition between the two.
Another option if you don't want to use the null_resource
work around with the CLI suggested above is to use the azapi provider:
resource "azapi_update_resource" "dcr" {
type = "Microsoft.OperationalInsights/workspaces@2023-09-01"
resource_id = azurerm_log_analytics_workspace.main.id
body = {
properties = {
defaultDataCollectionRuleResourceId = azurerm_monitor_data_collection_rule.default_dcr.id
}
}
}
You'll also need to ignore changes in the main log analytics resource
resource "azurerm_log_analytics_workspace" "main" {
...
lifecycle {
ignore_changes = [data_collection_rule_id]
}
}
Is there an existing issue for this?
Community Note
Description
When creating a azurerm_log_analytics_workspace and azurerm_monitor_data_collection_rule there is no way of connecting both, currently we are forced to use az cli to connect both
It would be great to have a dedicated resource for that.
New or Affected Resource(s)/Data Source(s)
azurerm_log_analytics_workspace_data_rule_connection
Potential Terraform Configuration
References
No response