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

Wrong Dependency Generated for AKS Monitor #458

Open
soumikcal opened this issue Oct 2, 2023 · 1 comment
Open

Wrong Dependency Generated for AKS Monitor #458

soumikcal opened this issue Oct 2, 2023 · 1 comment
Labels
question Further information is requested upstream-provider

Comments

@soumikcal
Copy link

When AKS has monitor attached then depends_on field for Monitor is not AKS RES. So failing to apply
resource. "azurerm_monitor_action_group" should depend on AKS, "azurerm_monitor_metric_alert" should depend on "azurerm_monitor_action_group". But when exported its depends on Resource Group only which leads to fail when apply...

"azurerm_monitor_action_group" "res-12" {
name = "RecommendedAlertRules-AG-1"
resource_group_name = "terragen-rg"
short_name = "recalert1"
email_receiver {
email_address = "soumik.mukherjee@ascendion.com"
name = "Email_-EmailAction-"
use_common_alert_schema = true
}
depends_on = [
azurerm_resource_group.res-0,
]
}
resource "azurerm_monitor_metric_alert" "res-13" {
auto_mitigate = false
frequency = "PT5M"
name = "CPU Usage Percentage - terragen-aks"
resource_group_name = "terragen-rg"
scopes = ["/subscriptions/ceaa9e66-993b-4b12-b3c2-e13d7ec61e71/resourcegroups/terragen-rg/providers/Microsoft.ContainerService/managedClusters/terragen-aks"]
action {
action_group_id = "/subscriptions/ceaa9e66-993b-4b12-b3c2-e13d7ec61e71/resourceGroups/terragen-rg/providers/Microsoft.Insights/ActionGroups/RecommendedAlertRules-AG-1"
}
criteria {
aggregation = "Average"
metric_name = "node_cpu_usage_percentage"
metric_namespace = "Microsoft.ContainerService/managedClusters"
operator = "GreaterThan"
threshold = 95
}
depends_on = [
azurerm_resource_group.res-0,
]
}
resource "azurerm_monitor_metric_alert" "res-14" {
auto_mitigate = false
frequency = "PT5M"
name = "Memory Working Set Percentage - terragen-aks"
resource_group_name = "terragen-rg"
scopes = ["/subscriptions/ceaa9e66-993b-4b12-b3c2-e13d7ec61e71/resourcegroups/terragen-rg/providers/Microsoft.ContainerService/managedClusters/terragen-aks"]
action {
action_group_id = "/subscriptions/ceaa9e66-993b-4b12-b3c2-e13d7ec61e71/resourceGroups/terragen-rg/providers/Microsoft.Insights/ActionGroups/RecommendedAlertRules-AG-1"
}
criteria {
aggregation = "Average"
metric_name = "node_memory_working_set_percentage"
metric_namespace = "Microsoft.ContainerService/managedClusters"
operator = "GreaterThan"
threshold = 100
}
depends_on = [
azurerm_resource_group.res-0,
]
}

@magodo magodo added question Further information is requested upstream-provider labels Oct 11, 2023
@magodo
Copy link
Collaborator

magodo commented Oct 11, 2023

@soumikcal Thank you for submitting this!

The logic of how aztfexport resolve the dependency is that it traverse the properties of each resource. If there is any string property that case sensitively equals to any tracked resource id in TF, then that trakced resource is added as a dependency.

This explains why azurerm_monitor_action_group is just azurerm_resource_group.

Also, as the action_group_id of the azurerm_monitor_metric_alert has the wrong case, e.g. "/subscriptions/ceaa9e66-993b-4b12-b3c2-e13d7ec61e71/resourceGroups/terragen-rg/providers/Microsoft.Insights/ActionGroups/RecommendedAlertRules-AG-1" (should be lower cased a). The dependency on azurerm_monitor_action_group is also not added. This is a provider bug needs to be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested upstream-provider
Projects
None yet
Development

No branches or pull requests

2 participants