Skip to content

Commit 1c03a8e

Browse files
authored
feat: (IAC-638): Added new optional Diagnostic Setting for AKS clusters (#276)
1 parent b8e9efa commit 1c03a8e

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

monitor.tf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,43 @@ resource "azurerm_log_analytics_solution" "viya4" {
3737
tags = var.tags
3838

3939
}
40+
41+
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_diagnostic_setting
42+
43+
resource "azurerm_monitor_diagnostic_setting" "audit" {
44+
count = var.create_aks_azure_monitor ? 1 : 0
45+
46+
name = "${var.prefix}-monitor_diagnostic_setting"
47+
target_resource_id = module.aks.cluster_id
48+
log_analytics_workspace_id = azurerm_log_analytics_workspace.viya4[0].id
49+
50+
dynamic "log" {
51+
iterator = log_category
52+
for_each = var.resource_log_category
53+
54+
content {
55+
category = log_category.value
56+
enabled = true
57+
58+
retention_policy {
59+
enabled = true
60+
days = var.log_retention_in_days
61+
}
62+
}
63+
}
64+
65+
dynamic "metric" {
66+
iterator = metric_category
67+
for_each = var.metric_category
68+
69+
content {
70+
category = metric_category.value
71+
enabled = true
72+
73+
retention_policy {
74+
enabled = true
75+
days = var.log_retention_in_days
76+
}
77+
}
78+
}
79+
}

variables.tf

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ variable "location" {
4141
default = "eastus"
4242
}
4343

44-
variable aks_cluster_sku_tier {
44+
variable "aks_cluster_sku_tier" {
4545
description = "The SKU Tier that should be used for this Kubernetes Cluster. Possible values are Free and Paid (which includes the Uptime SLA). Defaults to Free"
46-
default = "Free"
47-
type = string
46+
default = "Free"
47+
type = string
4848

4949
validation {
50-
condition = contains(["Free", "Paid"], var.aks_cluster_sku_tier)
50+
condition = contains(["Free", "Paid"], var.aks_cluster_sku_tier)
5151
error_message = "ERROR: Valid types are \"Free\" and \"Paid\"!"
5252
}
5353
}
@@ -364,7 +364,7 @@ variable "netapp_volume_path" {
364364

365365
variable "netapp_network_features" {
366366
description = "Indicates which network feature to use, accepted values are Basic or Standard, it defaults to Basic if not defined."
367-
type = string
367+
type = string
368368
default = "Basic"
369369
}
370370

@@ -439,7 +439,7 @@ variable "node_pools" {
439439
}
440440
}
441441

442-
# Azure Monitor
442+
# Azure Monitor - Undocumented
443443
variable "create_aks_azure_monitor" {
444444
type = bool
445445
description = "Enable Azure Log Analytics agent on AKS cluster"
@@ -488,6 +488,19 @@ variable "log_analytics_solution_promotion_code" {
488488
default = ""
489489
}
490490

491+
## Azure Monitor Diagonostic setting - Undocumented
492+
variable "resource_log_category" {
493+
type = list(string)
494+
description = "List of all resource logs category types supported in Azure Monitor."
495+
default = ["kube-controller-manager", "kube-apiserver", "kube-scheduler"]
496+
}
497+
498+
variable "metric_category" {
499+
type = list(string)
500+
description = "List of all metric category types supported in Azure Monitor."
501+
default = ["AllMetrics"]
502+
}
503+
491504
# BYO
492505
variable "resource_group_name" {
493506
type = string

0 commit comments

Comments
 (0)