# The query behind each alert, saved in the workspace under the alert's own # name, with the columns a responder reads first. locals { saved = merge( { for k, d in local.detections : "insider-${k}" => { display = d.doc query = "${replace(d.query, "ingestion_time() > ago(5m)", "TimeGenerated > ago(7d)")} | project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, ActivityStatusValue, _ResourceId | order by TimeGenerated desc" } }, local.reads ? { "insider-bulk-read" = { display = "Callers who read the most from the sensitive accounts in the last hour" query = replace(local.bulk_read_query, "| where Bytes > ${local.bulk_read_bytes}", "| order by Bytes desc") } } : {}, ) } resource "azurerm_log_analytics_saved_search" "insider" { for_each = local.saved name = each.key log_analytics_workspace_id = azurerm_log_analytics_workspace.insider.id category = "Insider data theft" display_name = each.value.display query = each.value.query tags = local.tags }