【问题标题】:Inappropriate value for attribute "triggers": map of string required属性“触发器”的值不合适:需要字符串映射
【发布时间】:2019-07-08 17:23:21
【问题描述】:

遇到错误“属性“触发器”的值不合适:需要字符串映射。”

尝试使用 local-exec 配置器,在这种情况下,它应该在创建特定资源之前触发“监视器”

resource "null_resource" "test_run" {
  provisioner "local-exec" {
    command     = "bin/script.sh"
    interpreter = ["bash", "-File"]
  }

  triggers {
    before = "${bigip_ltm_monitor.millenium}"
  }
}

resource "bigip_ltm_monitor" "millenium" {
  compatibility = "enabled"
  interval      = "5"
  name          = "/Common/https_mon"
  parent        = "/Common/https"
  receive       = "200"
  reverse       = "disabled"
  send          = "GET /health HTTP/1.1\r\nHost: xyz.com\r\nConnection: Close\r\n\r\n"
  timeout       = "16"
}

【问题讨论】:

  • 请分享monitor的完整millenium属性
  • @rflume 请看一下。
  • 错误消息有效:您有一个Map[Map[String]] 而不是Map[String] 用于triggers。这里有几件事:什么版本的 Terraform,你能terraform fmt你的配置让它可读吗?
  • 起初我以为是嵌套格式的 JSON,但它似乎是一种奇怪的 HCL 格式,显然是有效的。我已将其编辑为更规范的样式,以使其对 Terraform 的其他用户可读,但如果有充分的理由应该采用该格式,则将其回滚。
  • 现在我已将格式更改为更规范的 HCL 样式,看起来应该没问题,所以现在我担心该编辑使问题无效。如果您能详细说明您最初尝试以该格式使用 HCL 的原因,这可能会有所帮助。

标签: terraform


【解决方案1】:

triggers 参数的目的是指定一个字符串集合,null_resource 实现可以检查这些字符串的变化,以决定是否替换对象,从而重新运行配置程序。

如果您需要在创建bigip_ltm_monitor.millenium 之前创建null_resource.test_run,那么您需要在bigip_ltm_monitor 内以另一种方式编写依赖关系边。例如:

resource "bigip_ltm_monitor" "millenium" {
  compatibility = "enabled"
  interval      = "5"
  name          = "/Common/https_mon"
  parent        = "/Common/https"
  receive       = "200"
  reverse       = "disabled"
  send          = "GET /health HTTP/1.1\r\nHost: xyz.com\r\nConnection: Close\r\n\r\n"
  timeout       = "16"

  depends_on = [null_resource.test_run]
}

【讨论】:

    【解决方案2】:

    尝试在 bigip_ltm_monitor 资源中设置 depends_on = [null_resource.test_run]而不是null_resource 中设置 triggers{...}

    这让 Terraform 在监视器之前创建供应商资源。

    更多信息请参见Resource Dependencies

    【讨论】:

    • 这不是必需的,也不能回答问题。
    • @rflume 感谢您的建议。我知道这种解决方法,但我正在研究 bigip 提供程序并创建各种监视器、节点、池等。这里的想法是使触发器选项起作用,以便我可以在创建其他资源(如监视器和节点)之前执行 bash 脚本也没有使我的依赖关系树变得非常复杂。
    猜你喜欢
    • 2021-02-09
    • 2021-06-18
    • 2021-06-23
    • 1970-01-01
    • 2021-11-27
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    相关资源
    最近更新 更多