HiveBrain v1.2.0
Get Started
← Back to all entries
patternterraformMinor

Are multiline lists valid in Terraform?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
multilinearevalidliststerraform

Problem

I currently have the following.

module "module-name" {
  source                              = "./directory"
  environment                         = var.environment
  team_names                          = ["team-a", "team-b", "team-c", "team-d"]


This clearly makes the team_names line very long. Is it valid to change to this?

module "module-name" {
  source                              = "./directory"
  environment                         = var.environment
  team_names                          = [
                                          "team-a",
                                          "team-b",
                                          "team-c",
                                          "team-d"
                                        ]

Solution

Yes. According to Types and Values: Lists/Tuples

List literals can be split into multiple lines for readability, but always require a comma between values. A comma after the final value is allowed, but not required. Values in a list can be arbitrary expressions.

Source:

  • Terraform by HashiCorp. (n.d.). Types and Values - Configuration Language. [online] Available at: https://www.terraform.io/docs/language/expressions/types.html#lists-tuples [Accessed 28 Sep. 2021].



Context

StackExchange DevOps Q#14746, answer score: 7

Revisions (0)

No revisions yet.