generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
86 lines (75 loc) · 2.81 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* # sentinel_alert_rule
*
* This module deploys an analytic rule to Azure Sentinel.
*
* You'll need to provide the following:
* - Log Analytics Workspace ID
* - Query
* - Query Frequency
* - Query Period
* - Severity
* - Tactics
* - Trigger Operator
* - Trigger Threshold
* - Entity Mapping
* - Incident Configuration
*/
resource "random_uuid" "this" {
}
resource "azurerm_sentinel_alert_rule_scheduled" "this" {
description = var.description
display_name = var.display_name
enabled = var.enabled
log_analytics_workspace_id = var.workspace_id
name = coalesce(var.name, random_uuid.this.result)
query = var.query
query_frequency = var.query_frequency #"PT1H" "P1D" "PT5M"
query_period = var.query_period
severity = var.severity
suppression_duration = var.suppression_duration
suppression_enabled = var.suppression_enabled
tactics = var.tactics
techniques = var.techniques
trigger_operator = var.trigger_operator
trigger_threshold = var.trigger_threshold
custom_details = var.custom_details
event_grouping {
aggregation_method = var.event_grouping.aggregation_method
}
# a dynamic block only when alert_description is in the query
dynamic "alert_details_override" {
for_each = can(regex("alert_description", var.query)) ? [1] : []
content {
description_format = "{{alert_description}}"
}
}
# iterate over the list of entity_mapping and create a dynamic block for each one
dynamic "entity_mapping" {
for_each = var.entity_mapping
content {
entity_type = entity_mapping.value.entity_type
dynamic "field_mapping" {
for_each = entity_mapping.value.field_mapping
content {
column_name = field_mapping.value.column_name
identifier = field_mapping.value.identifier
}
}
}
}
dynamic "incident_configuration" {
for_each = [1]
content {
create_incident = var.incident_configuration.create_incident
grouping {
enabled = var.query_frequency != "PT5M" ? true : var.incident_configuration.grouping.enabled
entity_matching_method = var.incident_configuration.grouping.entity_matching_method
group_by_alert_details = var.incident_configuration.grouping.group_by_alert_details
group_by_custom_details = var.incident_configuration.grouping.group_by_custom_details
group_by_entities = var.incident_configuration.grouping.group_by_entities
lookback_duration = var.incident_configuration.grouping.lookback_duration
reopen_closed_incidents = var.incident_configuration.grouping.reopen_closed_incidents
}
}
}
}