表达的地形和多个列表

发布于 2025-01-27 14:45:02 字数 1470 浏览 2 评论 0原文

我想使用以下来表达式使用TF 0.13.7创建CloudWatch仪表板 变量:

variable "redis_replicas" {
  type = list(map(string))
  default = [
    {
      name   = "test-eucentral1-redis-001"
      region = "eu-central-1"
    },

locals {
  replicas = [for i in var.redis_replicas: i.name]
  regions = [for i in var.redis_replicas: i.region]

计划的资源

resource "aws_cloudwatch_dashboard" "cloudwatch_db_redis" {
  dashboard_name = "Redis-Performance"
  dashboard_body = jsonencode({
    widgets : concat(local.body1)
  })
}

  body1 = [ 
    {
      height = 6
      properties = {
        metrics = [ for replica in local.replicas : 
          [
            {
              expression = "m1"
              id         = "e1"
            },
          ], # getting error here 
          [
            "AWS/ElastiCache",
            "ClusterBasedCmds",
            "CacheClusterId",
            replica,
          ],
        ]
        view    = "timeSeries"
      }
      type  = "metric"
    }
  ]

使用

metrics = [for instance in var.redis_replicas : [
[],
[],
]

工作,但适用是失败的。

Error: Putting dashboard failed: InvalidParameterInput: The dashboard body is invalid, there are 50 validation errors:
[
  {
    "dataPath": "/widgets/9/properties/metrics/0/0",
    "message": "Invalid metric field type, only \"String\" type is allowed"
  },

知道如何结合这两个吗? 如果我在身体上做的话,它可以使用,但是我有不同的副本的图形。

I want to use following for expression to create CloudWatch dashboard using TF 0.13.7
Variables:

variable "redis_replicas" {
  type = list(map(string))
  default = [
    {
      name   = "test-eucentral1-redis-001"
      region = "eu-central-1"
    },

locals {
  replicas = [for i in var.redis_replicas: i.name]
  regions = [for i in var.redis_replicas: i.region]

resources

resource "aws_cloudwatch_dashboard" "cloudwatch_db_redis" {
  dashboard_name = "Redis-Performance"
  dashboard_body = jsonencode({
    widgets : concat(local.body1)
  })
}

  body1 = [ 
    {
      height = 6
      properties = {
        metrics = [ for replica in local.replicas : 
          [
            {
              expression = "m1"
              id         = "e1"
            },
          ], # getting error here 
          [
            "AWS/ElastiCache",
            "ClusterBasedCmds",
            "CacheClusterId",
            replica,
          ],
        ]
        view    = "timeSeries"
      }
      type  = "metric"
    }
  ]

Using

metrics = [for instance in var.redis_replicas : [
[],
[],
]

Plan works but apply is failing.

Error: Putting dashboard failed: InvalidParameterInput: The dashboard body is invalid, there are 50 validation errors:
[
  {
    "dataPath": "/widgets/9/properties/metrics/0/0",
    "message": "Invalid metric field type, only \"String\" type is allowed"
  },

Any idea how to combine those two?
It works if I do for in body but then I have different graphs for different replica.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文