Skip to main content
flatten(list) takes a list that may contain nested lists and returns a single flat tuple with all elements at the same level.

Signature

flatten(list list) tuple

Example

Each service declares its own set of test patterns. flatten collapses them into a single sequence for a unified test run:
variable "service_test_patterns" {
  description = "Test file patterns per service"
  type        = list(list(string))
  default = [
    ["./service/api/...", "./service/api/integration/..."],
    ["./service/worker/..."],
    ["./service/scheduler/...", "./service/scheduler/e2e/..."],
  ]
}

computed "all_test_patterns" {
  description = "All test patterns flattened"
  expression  = flatten(var.service_test_patterns)
}

task "test" {
  description = "Run all service tests"
  commands    = ["go test ${join(" ", computed.all_test_patterns)}"]
}
The nested lists become ["./service/api/...", "./service/api/integration/...", "./service/worker/...", ...].

Notes

  • flatten recurses through all levels of nesting.
  • The result is a tuple, not a list. Functions like join that accept lists also work with tuples.