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

kum*_*mar 2 terraform terraform-provider-aws

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

变量.tf

variable "aws_cluster_arn" {
  type = string
  
}

variable "aws_ecs_placement_strategy" {
  type = list(object)
}
Run Code Online (Sandbox Code Playgroud)

configuration.tfvars中

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

我收到以下错误:

错误:类型规范无效

在 Variables.tf 第 53 行,变量“aws_ecs_placement_strategy”中:
53:type = list(object)

Adi*_*l B 5

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

variable "aws_ecs_placement_strategy" {
  type = list(object({
     type = string,
     field = string
  }))
}
Run Code Online (Sandbox Code Playgroud)