Reputation: 2277
I have a file that has a list of strings, separated by a new line.
10.0.0.0
10.0.0.1
10.0.0.2
I would like to convert them into a List of type String, so that I can utilize them within my Terraform.
Is there a way to do this?
I can save the file as whatever format I like. I have been trying to save it as a yaml, then utilize yamldecode
to make this convertion to ['10.0.0.0', '10.0.0.1', '10.0.0.2']
but so far, I haven't been able to.
Is there a way to achieve this?
Any help on this would be appreciated!
Upvotes: 3
Views: 4423
Reputation: 16805
You can do something like this:
locals {
lines = [for line in split("\n", file("file.txt")): chomp(line)]
}
This will split the input based on newline (\n
) characters. chomp
will remove \r
characters in case your file is using CLRF
endings (if you are using Windows).
Upvotes: 4