2

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"
                                        ]

1 Answer 1

7

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:

3
  • 1
    Found the answer while writing the question so did not want it to go to waste :) Commented Sep 28, 2021 at 11:39
  • 1
    If you work with AWS/IAM + Terraform, you will see modules that have 1 IAM roles with 1 to many policies attached to it and it usually goes as a manual arn list or a data source holding that arn. Thats what I have seen in my work experience as big/long lists. So good job for finding this and its a valid answer! Commented Sep 28, 2021 at 12:38
  • 1
    These docs are written to describe specific situations in specific terms, but it might interest you to know a more general rule: when parsing expressions (the right-hand side of an = for an attribute inside a block) Terraform treats newlines as irrelevant whitespace inside both parentheses and square brackets, unless you undo that effect inside by opening braces (where the newline-sensitive processing comes back into effect again, so you can use newline-separated attribute syntax to define the object attributes). Commented Sep 28, 2021 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.