I have a section in my terraform module which reads text from multiple files and joins them together.
foo = join("\n", [
file('path/to/file1.txt'),
file('path/to/file2.txt'),
file('path/to/file3.txt'),
])
Its cumbersome to always list every file, and I would like to switch to using: fileset("path/to", "*.txt") to list all the files.
However, this gives me a list of file paths, which I can't give to file(). Is there some way I can run file() on each element of this list?
In other languages there is usually some map() function which is used to transform the elements of a collection, by calling a function on each item. I can't find anything like this in terraform. The closest thing I've found, is format_list() but that doesn't do what I need.