0

我正在结合使用pagerduty_ruleset_rule资源count来创建多个 PagerDuty 规则。每个规则都是从映射列表中设计count.index的。services


变量定义 -services映射列表(作为 a 传入var.services):

variable "services" {
  type        = list(object({ id = string, service_tags = list(string) }))
  description = "List of service IDs and tags to route events to"
}

资源定义 - pagerduty_ruleset_rule

resource "pagerduty_ruleset_rule" "rule" {
  count = length(var.services)

  ruleset  = pagerduty_ruleset.custom_ruleset.id
  position = count.index
  disabled = false
  conditions {
    operator = "or"
    subconditions {
      operator = "contains"
      parameter {
        path  = "payload.group"
        value = "service:${var.services[count.index].service_tags[0]}"
      }
    }
    subconditions {
      operator = "contains"
      parameter {
        path  = "payload.group"
        value = "service:${var.services[count.index].service_tags[1]}"
      }
    }
  }
  actions {
    route {
      value = var.services[count.index].id
    }
  }
}

请注意我是如何subconditionsservice_tags.

有没有办法subconditions根据service_tags列表的大小动态创建地图?

在上面的代码片段中,我假设列表的大小为 2(索引[0]& [1]),但我希望这是动态的 - 数量subconditions等于service_tags列表的大小。

4

0 回答 0