Hello All,
I am trying to create a dynamic datadog monitor using dynamic block for a list of apps.
I am getting below error.
Error: Unsupported block type
on dynamicmain.tf line 91, in resource “datadog_monitor” “monitor”:
91: dynamic “monitor”{
Code is below
resource “datadog_monitor” “monitor” {
type = “metric alert”
dynamic “monitor”{
for_each = var.my_app_monitors
content {
name = “{monitor.value}"
query = "{monitor.key} - {monitor.value}"
message = " we are in message for key {monitor.key}”
}
}
}
variable “my_app_monitors” {
default = {
“First” = “value1”
“Second” = “value2”
}
}
No one answered this?!? Wow. I’m sure you solved it by now, just in case:
resource "datadog_monitor" "monitor" {
for_each = { for monitor in local.monitors : monitor.name => monitor }
name = each.value.name
type = each.value.type
message = each.value.message
escalation_message = try(each.value.options.escalation_message, null)
query = each.value.query
monitor_thresholds {
ok = try(each.value.options.thresholds.ok, null)
warning = try(each.value.options.thresholds.warning, null)
critical = try(each.value.options.thresholds.critical, null)
critical_recovery = try(each.value.options.thresholds.critical_recovery, null)
}
# more values as needed
}
Note in my case, I am using the raw json from https://api.datadoghq.com/api/v1/monitor
. You may have your own datastructure, so you’ll need to adapt this from your datastructure.