# The query behind each alert, saved in the workspace under the alert's own # name and looking back a week, plus two for working a case. locals { saved = merge( { for k, d in local.detections : "entra-${k}" => { display = d.doc query = replace(d.query, "ingestion_time() > ago(5m)", "TimeGenerated > ago(7d)") } }, { entra-one-user = { display = "Everything one user did and every sign-in they made, last seven days" query = "let who = \"REPLACE-WITH-UPN\"; union isfuzzy=true (AuditLogs | where TimeGenerated > ago(7d) | where tostring(InitiatedBy.user.userPrincipalName) =~ who or tostring(TargetResources[0].userPrincipalName) =~ who | project TimeGenerated, Kind = \"audit\", What = OperationName, Result), (SigninLogs | where TimeGenerated > ago(7d) | where UserPrincipalName =~ who | project TimeGenerated, Kind = \"sign-in\", What = AppDisplayName, Result = ResultType, IPAddress, Location) | order by TimeGenerated desc" } entra-sign-ins-by-source = { display = "Sign-ins by user, address, and result, last 24 hours" query = "SigninLogs | where TimeGenerated > ago(1d) | summarize Attempts = count(), Failures = countif(ResultType != \"0\") by UserPrincipalName, IPAddress | order by Failures desc" } }, ) } resource "azurerm_log_analytics_saved_search" "entra" { for_each = local.saved name = each.key log_analytics_workspace_id = azurerm_log_analytics_workspace.entra.id category = "Identity provider signals" display_name = each.value.display query = each.value.query tags = local.tags }