Skip to content

Commit bf5adb4

Browse files
committed
Add diagnostics for asp
1 parent 5836ae0 commit bf5adb4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

code/infra/function.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ resource "azurerm_service_plan" "service_plan" {
1212
zone_balancing_enabled = false # Update to 'true' for production
1313
}
1414

15+
data "azurerm_monitor_diagnostic_categories" "diagnostic_categories_service_plan" {
16+
resource_id = azurerm_service_plan.service_plan.id
17+
}
18+
19+
resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting_service_plan" {
20+
name = "logAnalytics"
21+
target_resource_id = azurerm_service_plan.service_plan.id
22+
log_analytics_workspace_id = azurerm_log_analytics_workspace.log_analytics_workspace.id
23+
24+
dynamic "enabled_log" {
25+
iterator = entry
26+
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories_service_plan.log_category_groups
27+
content {
28+
category_group = entry.value
29+
retention_policy {
30+
enabled = true
31+
days = 30
32+
}
33+
}
34+
}
35+
36+
dynamic "metric" {
37+
iterator = entry
38+
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories_service_plan.metrics
39+
content {
40+
category = entry.value
41+
enabled = true
42+
retention_policy {
43+
enabled = true
44+
days = 30
45+
}
46+
}
47+
}
48+
}
49+
1550
resource "azapi_resource" "function" {
1651
type = "Microsoft.Web/sites@2022-09-01"
1752
parent_id = azurerm_resource_group.app_rg.id

0 commit comments

Comments
 (0)