【问题标题】:computed locals from variable in terraform v12 syntax从 terraform v12 语法中的变量计算局部变量
【发布时间】:2020-05-30 18:35:44
【问题描述】:

我正在尝试从变量创建计算的局部变量。
这个语法正确吗?
如果我在资源中调用for_each = locals.db_servicesterraform 会自动添加到依赖图中吗?

variable "services" {
    type = list(object)
}

locals {
    db_services = {
        for service in var.services:
        service.name => service
        if index(lookup(service, "storage", []), "postgres") > 0 && service.cluster == "service"
    }
}

resource "aws_ecs_task_definition" "rds_dump_task" {
  for_each = local.db_services

  family                = format("rds-dump-task-%s-%s", each.value.name, var.environment)
  container_definitions = data.template_file.container_definition[each.key].rendered
  task_role_arn         = format("arn:aws:iam::%s:role/%s-ecs-task-%s",
    var.account_id,
    each.value.name,
    var.environment
  )
}

【问题讨论】:

    标签: terraform


    【解决方案1】:

    语法有效! 此外,var.services 以 .json.tf 文件格式存储,效果非常好。

    【讨论】:

      猜你喜欢
      • 2018-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多