简体   繁体   中英

Terraform list of objects default values

I'm getting an error when I try to set default values for an object inside a list:

variable "routes" {
  type = list(object({
    destination_cidr_block = string
    blackhole = bool})
    default = {
      blackhole = "false"
      destination_cidr_block = ""
    })
  description = "a list of objects containing the cidr blocks of the dest and whether the cidr is a blackhole or not."
  default = null
}

When I run this, I get the below error:

Error: Missing argument separator

  on variables.tf line 21, in variable "routes":
  18:   type = list(object({
  19:     destination_cidr_block = string
  20:     blackhole = bool})
  21:     default = {

A comma is required to separate each function argument from the next.

Line 21 "default" is underlined in the error.

Setting defaults in this way works fine when it's just an object by itself. I don't know why it complains when the variable is a list of objects.

You may want to have it like this:

variable "routes" {
  type = list(object({
    destination_cidr_block = string
    blackhole              = bool
  }))
  default = [{
    blackhole              = "false"
    destination_cidr_block = ""
  }]
  description = "a list of objects containing the cidr blocks of the dest and whether the cidr is a blackhole or not."
}

You cannot really have a default inside a type.

I requested an object type default feature and they are now releasing Optional attributes for object type constraints into the next build of Terraform!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM