AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1137512
Accepted
Marshall Davis
Marshall Davis
Asked: 2023-07-17 23:55:01 +0800 CST2023-07-17 23:55:01 +0800 CST 2023-07-17 23:55:01 +0800 CST

如何使用动态阈值对 Datadog 监视器进行 Terraform

  • 772

我正在尝试从 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"
}

考虑到某些阈值可能已设置,也可能未设置,如何以这种方式添加动态属性?它们是否应该始终以0or 的形式存在"",并且可以选择性地被覆盖?

terraform
  • 1 1 个回答
  • 19 Views

1 个回答

  • Voted
  1. Best Answer
    Marshall Davis
    2023-07-18T23:29:49+08:002023-07-18T23:29:49+08:00

    简而言之,你不能。

    但是,您可以monitor_thresholds在所有情况下都包含具有默认值的嵌套架构。给出与问题中列出的相同格式:

    monitor_thresholds {
      critical = lookup(each.value["thresholds"], "critical", "")
      warning = lookup(each.value["thresholds"], "warning", "")
    }
    

    该lookup函数允许丢失密钥,并在丢失密钥时提供默认值。这可以通过条件扩展为更多可选部分。

    monitor_threshold_windows {
      recovery_window = lookup(each.value, "threshold_windows", null) != null ? lookup(each.value["threshold_windows"], "recovery_window", "") : ""
    }
    
    • 0

相关问题

  • 子网没有在 azure 上使用 terraform 创建,如何解决?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve