Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add azure monitor workspace to aks template #407

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions modules/terraform/azure/aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions modules/terraform/azure/aks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading