This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
62 lines (52 loc) · 2.02 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
#--------------------------------------
# Resource Group and other resoruces
#--------------------------------------
data "azurerm_resource_group" "rg" {
name = var.resource_group_name
}
data "azurerm_log_analytics_workspace" "logws" {
count = var.log_analytics_workspace_name != null ? 1 : 0
name = var.log_analytics_workspace_name
resource_group_name = data.azurerm_resource_group.rg.name
}
data "azurerm_storage_account" "storeacc" {
count = var.hub_storage_account_name != null ? 1 : 0
name = var.hub_storage_account_name
resource_group_name = data.azurerm_resource_group.rg.name
}
#---------------------------------
# Azure Automation Account
#---------------------------------
resource "azurerm_automation_account" "aauto" {
name = var.automation_account_name
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
sku_name = var.sku_name
tags = merge({ "ResourceName" = format("%s", var.automation_account_name) }, var.tags, )
}
#---------------------------------------------------------------
# azurerm monitoring diagnostics - automation account
#---------------------------------------------------------------
resource "azurerm_monitor_diagnostic_setting" "acc" {
count = var.log_analytics_workspace_name != null && var.hub_storage_account_name != null ? 1 : 0
name = lower("aacc-${var.automation_account_name}-diag")
target_resource_id = azurerm_automation_account.aauto.id
storage_account_id = data.azurerm_storage_account.storeacc.0.id
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.logws.0.id
dynamic "log" {
for_each = var.auto_diag_logs
content {
category = log.value
enabled = true
retention_policy {
enabled = false
}
}
}
metric {
category = "AllMetrics"
retention_policy {
enabled = false
}
}
}