generated from tothenew/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_locals.tf
40 lines (32 loc) · 1.63 KB
/
_locals.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
locals {
enabled = length(var.logs_destinations_ids) > 0
log_categories = [
for log in
(
var.log_categories != null ?
var.log_categories :
try(data.azurerm_monitor_diagnostic_categories.main[0].log_category_types, [])
) : log if !contains(var.excluded_log_categories, log)
]
metric_categories = (
var.metric_categories != null ?
var.metric_categories :
try(data.azurerm_monitor_diagnostic_categories.main[0].metrics, [])
)
metrics = {
for metric in try(data.azurerm_monitor_diagnostic_categories.main[0].metrics, []) : metric => {
enabled = contains(local.metric_categories, metric)
}
}
storage_id = coalescelist([for r in var.logs_destinations_ids : r if contains(split("/", lower(r)), "microsoft.storage")], [null])[0]
log_analytics_id = coalescelist([for r in var.logs_destinations_ids : r if contains(split("/", lower(r)), "microsoft.operationalinsights")], [null])[0]
eventhub_authorization_rule_id = coalescelist([for r in var.logs_destinations_ids : split("|", r)[0] if contains(split("/", lower(r)), "microsoft.eventhub")], [null])[0]
eventhub_name = coalescelist([for r in var.logs_destinations_ids : try(split("|", r)[1], null) if contains(split("/", lower(r)), "microsoft.eventhub")], [null])[0]
log_analytics_destination_type = local.log_analytics_id != null ? var.log_analytics_destination_type : null
}
locals {
# Naming locals/constants
name_prefix = lower(var.name_prefix)
name_suffix = lower(var.name_suffix)
diag_name = coalesce(var.custom_name, var.use_caf_naming ? data.azurecaf_name.diag.result : data.azurecaf_name.diag.name)
}