generated from equinor/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
77 lines (61 loc) · 2.56 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
locals {
diagnostic_setting_metric_categories = ["AllMetrics"]
}
resource "azurerm_eventgrid_system_topic" "this" {
name = var.system_topic_name
resource_group_name = var.resource_group_name
location = var.location
source_arm_resource_id = var.source_arm_resource_id
topic_type = var.topic_type
tags = var.tags
}
resource "azurerm_eventgrid_system_topic_event_subscription" "this" {
for_each = var.event_subscriptions
name = each.value["name"]
system_topic = azurerm_eventgrid_system_topic.this.name
resource_group_name = azurerm_eventgrid_system_topic.this.resource_group_name
included_event_types = each.value["included_event_types"]
event_delivery_schema = "EventGridSchema"
dynamic "azure_function_endpoint" {
for_each = each.value["azure_function_endpoint"] != null ? [each.value["azure_function_endpoint"]] : []
content {
function_id = azure_function_endpoint.value["function_id"]
max_events_per_batch = 1
preferred_batch_size_in_kilobytes = 64
}
}
dynamic "storage_queue_endpoint" {
for_each = each.value["storage_queue_endpoint"] != null ? [each.value["storage_queue_endpoint"]] : []
content {
storage_account_id = storage_queue_endpoint.value["storage_account_id"]
queue_name = storage_queue_endpoint.value["queue_name"]
}
}
dynamic "webhook_endpoint" {
for_each = each.value["webhook_endpoint"] != null ? [each.value["webhook_endpoint"]] : []
content {
url = webhook_endpoint.value["url"]
}
}
}
resource "azurerm_monitor_diagnostic_setting" "this" {
name = var.diagnostic_setting_name
target_resource_id = azurerm_eventgrid_system_topic.this.id
log_analytics_workspace_id = var.log_analytics_workspace_id
# Ref: https://registry.terraform.io/providers/hashicorp/azurerm/3.65.0/docs/resources/monitor_diagnostic_setting#log_analytics_destination_type
log_analytics_destination_type = null
dynamic "enabled_log" {
for_each = toset(var.diagnostic_setting_enabled_log_categories)
content {
category = enabled_log.value
}
}
dynamic "metric" {
for_each = toset(concat(local.diagnostic_setting_metric_categories, var.diagnostic_setting_enabled_metric_categories))
content {
# Azure expects explicit configuration of both enabled and disabled metric categories.
category = metric.value
enabled = contains(var.diagnostic_setting_enabled_metric_categories, metric.value)
}
}
}