diff --git a/modules/terraform/azure/aks/main.tf b/modules/terraform/azure/aks/main.tf index e4688aa7d..ff052e6af 100644 --- a/modules/terraform/azure/aks/main.tf +++ b/modules/terraform/azure/aks/main.tf @@ -76,6 +76,12 @@ resource "azurerm_kubernetes_cluster" "aks" { } } + addon_profile { + azure_monitor_metrics { + enabled = true + } + } + oidc_issuer_enabled = var.aks_config.oidc_issuer_enabled workload_identity_enabled = var.aks_config.workload_identity_enabled kubernetes_version = var.aks_config.kubernetes_version @@ -110,6 +116,53 @@ resource "azurerm_role_assignment" "aks_on_subnet" { principal_id = azurerm_kubernetes_cluster.aks.identity[0].principal_id } +resource "azurerm_monitor_workspace" "ama_workspace" { + name = var.addons_config.ama_workspace.name + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location +} + +resource "azurerm_monitor_data_collection_endpoint" "ama_workspace" { + name = var.addons_config.ama_workspace.data_collection_endpoint.name + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + kind = var.addons_config.ama_workspace.data_collection_endpoint.kind +} + +resource "azurerm_monitor_data_collection_rule" "ama_workspace" { + name = var.addons_config.ama_workspace.data_collection_rule.name + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.example.id + kind = var.addons_config.ama_workspace.data_collection_rule.kind + + destinations { + monitor_account { + monitor_account_id = azurerm_monitor_workspace.ama_workspace.id + name = vars.addons_config.ama_workspace.data_collection_rule.destinations.monitor_account.name + } + } + + data_flow { + streams = var.addons_config.ama_workspace.data_collection_rule.data_flow.streams + destinations = [vars.addons_config.ama_workspace.data_collection_rule.destinations.monitor_account.name] + } + + data_sources { + prometheus_forwarder { + streams = var.addons_config.ama_workspace.data_collection_rule.data_flow.streams + name = var.addons_config.ama_workspace.data_collection_rule.data_sources.prometheus_forwarder.name + } + } +} + +resource "azurerm_monitor_data_collection_rule_association" "ama_workspace" { + name = var.addons_config.ama_workspace.data_collection_rule_association.name + target_resource_id = azurerm_kubernetes_cluster.example.id + data_collection_rule_id = azurerm_monitor_data_collection_rule.example.id + description = var.addons_config.ama_workspace.data_collection_rule_association.description +} + resource "local_file" "kube_config" { filename = "/tmp/${azurerm_kubernetes_cluster.aks.fqdn}" content = azurerm_kubernetes_cluster.aks.kube_config_raw diff --git a/modules/terraform/azure/aks/variables.tf b/modules/terraform/azure/aks/variables.tf index fc93f41b8..ed64f0e99 100644 --- a/modules/terraform/azure/aks/variables.tf +++ b/modules/terraform/azure/aks/variables.tf @@ -30,6 +30,41 @@ variable "subnets" { default = {} } +variable "addons_config" { + type = object({ + ama_workspace = object({ + name = optional(string, "loganalyticsworkspace") + data_collection_endpoint = object({ + name = optional(string, "ama-dce") + kind = optional(string, "Linux") + }) + data_collection_rule = object({ + name = optional(string, "ama-dcr") + kind = optional(string, "Linux") + destinations = object({ + monitor_account = object({ + monitor_account_id = string + name = optional(string, "MonitoringAccount1") + }) + }) + data_flow = object({ + streams = list(string) + }) + data_sources = object({ + prometheus_forwarder = object({ + name = optional(string, "PrometheusDataSource") + }) + }) + }) + data_collection_rule_association = object({ + name = optional(string, "ama-dcra") + target_resource_id = string + data_collection_rule_id = string + description = optional(string, "Association of data collection rule with AKS cluster.") + }) + }) +} + variable "aks_config" { type = object({ role = string