Skip to content

Commit

Permalink
removed prometheus managed
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolagospagopa committed Aug 24, 2023
1 parent ccb30fd commit 203fc06
Showing 1 changed file with 56 additions and 78 deletions.
134 changes: 56 additions & 78 deletions src/aks-platform/03_prometheus_managed.tf
Original file line number Diff line number Diff line change
@@ -1,80 +1,58 @@
resource "azurerm_monitor_workspace" "prometheus_amw" {
name = local.monitor_log_analytics_workspace_prometheus_name
location = azurerm_resource_group.rg_aks.location
resource_group_name = azurerm_resource_group.rg_aks.name
# resource "azurerm_monitor_workspace" "prometheus_amw" {
# name = local.monitor_log_analytics_workspace_prometheus_name
# location = azurerm_resource_group.rg_aks.location
# resource_group_name = azurerm_resource_group.rg_aks.name

# tags = var.tags
# }

# resource "azurerm_monitor_data_collection_endpoint" "prometheus_dce" {
# name = "${local.project}-prometheus-dce"
# location = azurerm_resource_group.rg_aks.location
# resource_group_name = azurerm_resource_group.rg_aks.name
# kind = "Linux"
# }

# resource "azurerm_monitor_data_collection_rule" "prometheus_dcr" {
# name = "${local.project}-prometheus-dcr"
# location = azurerm_resource_group.rg_aks.location
# resource_group_name = azurerm_resource_group.rg_aks.name
# data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.prometheus_dce.id
# kind = "Linux"

# destinations {
# monitor_account {
# monitor_account_id = azurerm_monitor_workspace.prometheus_amw.id
# name = "monitoring_account_prometheus"
# }
# }

# data_flow {
# streams = ["Microsoft-PrometheusMetrics"]
# destinations = ["monitoring_account_prometheus"]
# }

# data_sources {
# prometheus_forwarder {
# streams = ["Microsoft-PrometheusMetrics"]
# name = "PrometheusDataSource"
# }
# }

# description = "DCR for Azure Monitor Metrics Profile (Managed Prometheus)"
# depends_on = [
# azurerm_monitor_data_collection_endpoint.prometheus_dce,
# ]
# }

# resource "azurerm_monitor_data_collection_rule_association" "dcra" {
# name = "${local.project}-prometheus-dcra"
# target_resource_id = module.aks[0].id
# data_collection_rule_id = azurerm_monitor_data_collection_rule.prometheus_dcr.id
# description = "Association of data collection rule. Deleting this association will break the data collection for this AKS Cluster."
# depends_on = [
# azurerm_monitor_data_collection_rule.prometheus_dcr
# ]
# }

tags = var.tags
}

resource "azurerm_monitor_data_collection_endpoint" "prometheus_dce" {
name = "${local.project}-prometheus-dce"
location = azurerm_resource_group.rg_aks.location
resource_group_name = azurerm_resource_group.rg_aks.name
kind = "Linux"
}

resource "azurerm_monitor_data_collection_rule" "prometheus_dcr" {
name = "${local.project}-prometheus-dcr"
location = azurerm_resource_group.rg_aks.location
resource_group_name = azurerm_resource_group.rg_aks.name
data_collection_endpoint_id = azurerm_monitor_data_collection_endpoint.prometheus_dce.id
kind = "Linux"

destinations {
monitor_account {
monitor_account_id = azurerm_monitor_workspace.prometheus_amw.id
name = "monitoring_account_prometheus"
}
}

data_flow {
streams = ["Microsoft-PrometheusMetrics"]
destinations = ["monitoring_account_prometheus"]
}

data_sources {
prometheus_forwarder {
streams = ["Microsoft-PrometheusMetrics"]
name = "PrometheusDataSource"
}
}

description = "DCR for Azure Monitor Metrics Profile (Managed Prometheus)"
depends_on = [
azurerm_monitor_data_collection_endpoint.prometheus_dce,
]
}

resource "azurerm_monitor_data_collection_rule_association" "dcra" {
name = "${local.project}-prometheus-dcra"
target_resource_id = module.aks[0].id
data_collection_rule_id = azurerm_monitor_data_collection_rule.prometheus_dcr.id
description = "Association of data collection rule. Deleting this association will break the data collection for this AKS Cluster."
depends_on = [
azurerm_monitor_data_collection_rule.prometheus_dcr
]
}

#
# Enable prometheus monitoring for AKS cluster
#
resource "null_resource" "enable_prometheus_monitoring" {
triggers = {
AKS_NAME = module.aks[0].name
AKS_RESOURCE_GROUP = azurerm_resource_group.rg_aks.name
AMW_ID = azurerm_monitor_workspace.prometheus_amw.id
}

depends_on = [
module.aks[0]
]

provisioner "local-exec" {
command = <<EOF
az aks update --enable-azure-monitor-metrics \
-n ${self.triggers.AKS_NAME} \
-g ${self.triggers.AKS_RESOURCE_GROUP} \
--azure-monitor-workspace-resource-id ${self.triggers.AMW_ID}
EOF
}
}

0 comments on commit 203fc06

Please sign in to comment.