Documentation error

Terraform newbie here, but I think I found a mistake in a code example in the docs. Is this the correct place to share or is there a better forum? I saw some github issues opened regarding documentation, but wanted to check here first.

Hello @mikeassel,

Discuss is a great place to engage our team with any questions you have about HashiCorp tools.

Which code example(s) are you seeing that have errors? If you are able to provide links to those errors, Iā€™d be happy to help you out further!

1 Like

Thanks @onlydole. The example in question is found at https://www.terraform.io/docs/configuration/functions/flatten.html. The example is:

variable "networks" {
  type = map(object({
    cidr_block = string
    subnets = map(object({
      cidr_block = string
    })
  })
}

I get a syntax error when I use this. Seems like additional parenthesis are needed at the end of the 2nd and 3rd to last lines, like so:

variable "networks" {
  type = map(object({
    cidr_block = string
    subnets = map(object({
      cidr_block = string
    }))
  }))
}

Adding these extra parentheses works for me.

Second question, can you provide an example of a variable that would work for this? I was trying to test this but kept getting a syntax error and Iā€™m not sure what Iā€™m doing wrong. Thanks, Mike

Howdy @mikeassel,

Ah! What version of Terraform are you using currently?

Iā€™ve been testing the 0.13-beta2 version recently, and the following ā€œdefaultā€ values will work for 0.12.x and 0.13.x versions.

Let me know if that helps, and I will do some research into the docs to see if thereā€™s any context that Iā€™m missing!

variable "networks" {
  type = object({
    cidr_block = string
    subnets = object({
      cidr_block = string
    })
  })

default = {
    cidr_block = "10.0.1.0/16",
    subnets = {
      cidr_block = "10.0.1.0/24",
      cidr_block = "10.0.2.0/24",
      cidr_block = "10.0.3.0/24"
    }
  }
}

Iā€™m on 0.12.24. Thanks for the example variable! I will test that out and let you know.

2 Likes