Want condition in below dynamic resource, please help me how to achieve it
This is the main code
locals {
oft_cfc_k8s_alerts_tmp = concat(
var.oft_cfc_k8s_generic_alerts,
var.oft_cfc_k8s_system_addons_alerts,
var.oft_cfc_k8s_indirect_user_facing_addons_alerts,
var.oft_cfc_k8s_direct_user_facing_addons_alerts,
var.oft_cfc_k8s_hosts_alerts)
}
// flatten the combined vars to create new var of all alerts
// with key as mgmt zone id to loop over
locals {
oft_cfc_k8s_alerts = flatten([
for alert_key, value in local.oft_cfc_k8s_alerts_tmp : [
for mgmt_zone_key in value.mgmt_zone_id : {
key_id = alert_key
alert_name = value.alert_name
alert_description = value.alert_description
alert_condition = value.alert_condition
alerting_on_missing_data = value.alerting_on_missing_data
aggregation_type = value.aggregation_type
dealerting_samples = value.dealerting_samples
description_severity = value.description_severity
enabled = value.enabled
metric_id = value.metric_id
mgmt_zone_id = mgmt_zone_key
primary_dimension_key = value.primary_dimension_key
prefix = value.prefix
severity = value.severity
samples = value.samples
threshold = value.threshold
unit = value.unit
violating_samples = value.violating_samples
dimensions = value.dimensions == null ? {} : value.dimensions
}
]
])
}
resource "dynatrace_custom_anomalies" "oft_cfc_k8s_alerts" {
for_each = {
for value in local.oft_cfc_k8s_alerts : "${value.key_id}.${value.mgmt_zone_id }" => value
}
name = format("%s-%s-%s-%s", each.value.alert_name, each.value.mgmt_zone_id == "-abcd" ? "npn" : "prod" , each.value.description_severity, each.value.prefix)
description = format("[%s] %s", each.value.description_severity, each.value.alert_description)
primary_dimension_key = each.value.primary_dimension_key
enabled = each.value.enabled
aggregation_type = each.value.aggregation_type
metric_id = each.value.metric_id
severity = each.value.severity
scopes {
management_zone {
id = each.value.mgmt_zone_id
}
}
strategy {
static {
alert_condition = each.value.alert_condition
alerting_on_missing_data = each.value.alerting_on_missing_data
dealerting_samples = each.value.dealerting_samples
samples = each.value.samples
threshold = each.value.threshold
unit = each.value.unit
violating_samples = each.value.violating_samples
}
}
// nested loop for dynamic resources
dynamic "dimensions" {
for_each = each.value.dimensions
content {
string {
key = each.value.dimensions.key
filter {
operator = "EQUALS"
value = each.value.dimensions.value
}
}
}
}
}
So want to change below :-
dynamic "dimensions" {
for_each = each.value.dimensions
content {
entity { "== This need to be change according to var file, if loop is running on var.oft_cfc_k8s_hosts_alerts then it is entity , apart from that it is string"
key = each.value.dimensions.key
filter {
operator = "EQUALS"
value = each.value.dimensions.value
}
}
}
}