我正在尝试从 DataDog 提供程序创建许多资源。我希望为每种资源定义尽可能少的内容。对于许多属性来说,都有一些合理的默认值。我很难决定如何处理监视器阈值,特别是有些阈值可能是可选的。
resource "datadog_monitor" "monitor" {
for_each = {
faulty_deploy = {
message = "A deployment failed."
name = "Deployment Failure"
query = "someLongQuery"
type = "alert"
thresholds = {critical = "0"}
}
}
message = each.value["message"]
query = each.value["query"]
name = each.value["name"]
type = each.value["type"]
escalation_message = coalesce(each.value["escalation_message"], "")
evaluation_delay = coalesce(each.value["evaluation_delay"], "0")
include_tags = coalesce(each.value["include_tags"],"true")
dynamic "monitor_thresholds" {
for_each = each.value["thresholds"]
iterator = threshold
content {
# Dynamically adding these properties is the issue.
"${threshold.key}" = threshold.value
}
}
# These and more would use coalesce to set defaults.
new_group_delay = "60"
notify_audit = "false"
on_missing_data = "default"
priority = "0"
renotify_interval = "0"
renotify_occurrences = "0"
require_full_window = "false"
tags = []
timeout_h = "0"
}
考虑到某些阈值可能已设置,也可能未设置,如何以这种方式添加动态属性?它们是否应该始终以0
or 的形式存在""
,并且可以选择性地被覆盖?