1
votes

In Terraform, how do we define a list of objects?

variables.tf

variable "aws_cluster_arn" {
  type = string
  
}

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

in configuration.tfvars

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

I am getting following error:

Error: Invalid type specification

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

1

1 Answers

2
votes

When defining an object type, you should specify all of the object's fields and their types like so:

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