Round brackets without functionname - what is this?

locals {
  test  = [
    { password = "test1" },
    { password = "test2" },
    { password = "test3" }
  ]
}

output "test" {
  value = (local.test)[*].password
}
...
Outputs:

test = [
  "test1",
  "test2",
  "test3",
]

I saw this syntax, where parentheses without a function name - (local.test).

They are not needed there, but everything works with it.

I want to understand what it is?

They are simply parentheses in the standard mathematical sense, which has carried over into many computer languages - meaning nothing at all other than grouping to control the order of operations.

$ terraform console
> 1 + 2
3
> (1 + 2)
3
> 1 + 2 / 1000
1.002
> (1 + 2) / 1000
0.003
1 Like

Indeed!

I just wanted to add that in this case those parentheses seem to be totally redundant, because if you removed them the precedence of the operations would still be the same.

I suspect the original author of this configuration was feeling uncertain about how Terraform’s operator precedence is defined and so added these parentheses “just to make sure”, but I would recommend removing them to avoid similar confusion for other readers in future. The following should be exactly equivalent:

output "test" {
  value = local.test[*].password
}
1 Like