In a previous blog post (https://msandbu.org/automating-azure-sentinel-deployment-using-terraform-and-powershell/) I wrote how about you can use Terraform to automate the setup of Azure Sentinel and Log Analytics. The issue back then, was that you couldn’t automate Sentinel Analytics rules which you still needed to maintain using a third-party PowerShell module.
NOTE: I’m working on publishing a Terraform module for Azure Sentinel which can be used to automate Sentinel with the required configuration.
Now with the latest addition of the AzureRM Provider, we can now automate Sentinel rules as well using the resources
azurerm_sentinel_alert_rule_scheduled
azurerm_sentinel_alert_rule_ms_security_incident
Which you can see here –> https://www.terraform.io/docs/providers/azurerm/r/sentinel_alert_rule_ms_security_incident.html with these you can automate both Scheduled Analytics rules and also built-in security alert rules based upon Microsoft products.
Example Built-in incident alert rule. Where the resource supportes different type of product filters.
severity_filter = [“High”]
And severity filter can be High, Medium, Low and Informational.
name = “example”
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
display_name = “example”
severity = “High”
query = <<QUERY
AzureActivity |
where OperationName == “Create or Update Virtual Machine” or OperationName ==”Create Deployment” |
where ActivityStatus == “Succeeded” |
make-series dcount(ResourceId) default=0 on EventSubmissionTimestamp in range(ago(7d), now(), 1d) by Caller
QUERY
name = “example-resources”
location = “West Europe”
}resource “azurerm_log_analytics_workspace” “example” {
name = “example-workspace”
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku = “pergb2018”
}resource “azurerm_sentinel_alert_rule_ms_security_incident” “example” {
name = “example-ms-security-incident-alert-rule”
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
product_filter = “Microsoft Cloud App Security”
display_name = “example rule”
severity_filter = [“High”]
}
name = “example”
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
display_name = “example”
severity = “High”
query = <<QUERY
AzureActivity |
where OperationName == “Create or Update Virtual Machine” or OperationName ==”Create Deployment” |
where ActivityStatus == “Succeeded” |
make-series dcount(ResourceId) default=0 on EventSubmissionTimestamp in range(ago(7d), now(), 1d) by Caller
QUERY
}
There are still some limitations that you need to be aware of that is not supported by the Terraform resource.
name = “customrule2”
log_analytics_workspace_id = azurerm_log_analytics_workspace.rgcore-la.id
display_name = “customrule1”
severity = “High”
query_frequency = “PT5H”
query_period = “PT5H”
tactics = [“Discovery”]
trigger_operator = “GreaterThan”
trigger_threshold = “1”query = <<QUERY
AzureActivity |
where OperationName == “Create or Update Virtual Machine” or OperationName ==”Create Deployment” |
where ActivityStatus == “Succeeded” |
make-series dcount(ResourceId) default=0 on EventSubmissionTimestamp in range(ago(7d), now(), 1d) by Caller
QUERY
}