在 Terraform 中,如何定义对象列表?

In Terraform, how can I define a list of objects?

在 Terraform 中,我们如何定义对象列表?

variables.tf

variable "aws_cluster_arn" {
  type = string
  
}

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

configuration.tfvars

aws_ecs_placement_strategy=(object({type="spread",field="attribute:ecs.availability-zone"}),object({type="BinPack",field="CPU"}))

我收到以下错误:

Error: Invalid type specification

on variables.tf line 53, in variable "aws_ecs_placement_strategy":
53: type = list(object)

定义 object 类型时,您应该指定 object 的所有字段及其类型,如下所示:

variable "aws_ecs_placement_strategy" {
  type = list(object({
     type = string,
     field = string
  }))
}