Hello, hope someone can help me to develop condition for dynamic block. I’m trying to create a code for generating optional warning threshold in newrelic_nrql_alert_condition
(newrelic
provider). I’m using nested map for supplying argument values:
nr_nrql_condition = {
"nrql1" = {
policy = "policy1"
query = "SELECT average(duration) FROM Transaction where appName = 'App1'"
critical_threshold = {
operator = "above"
threshold = 3
threshold_duration = 300
threshold_occurrences = "all"
}
warning_threshold = {
operator = "above"
threshold = 1
threshold_duration = 300
threshold_occurrences = "all"
}
},
"nrql2" = {
policy = "policy1"
query = "SELECT average(duration) FROM Transaction where appName = 'App2'"
critical_threshold = {
operator = "above"
threshold = 7
threshold_duration = 300
threshold_occurrences = "all"
}
warning_threshold = {}
},
}
and the below is the extract of the code for creating the resource
resource "newrelic_nrql_alert_condition" "foo" {
for_each = var.nr_nrql_condition
...
critical {
operator = lookup(each.value["critical_threshold"], "operator")
threshold = lookup(each.value["critical_threshold"], "threshold")
threshold_duration = lookup(each.value["critical_threshold"], "threshold_duration")
threshold_occurrences = lookup(each.value["critical_threshold"], "threshold_occurrences")
}
dynamic "warning" {
for_each = each.value["warning_threshold"] != {} ? [1] : []
content {
operator = lookup(each.value["warning_threshold"], "operator")
threshold = lookup(each.value["warning_threshold"], "threshold")
threshold_duration = lookup(each.value["warning_threshold"], "threshold_duration")
threshold_occurrences = lookup(each.value["warning_threshold"], "threshold_occurrences")
}
}
}
dynamic "warning"
block only works if warning_threshold
map is defined with valid key/values parameters. I’m struggling to find a way to create condition to skip "warning"
block if warning_threshold = {}