Mazzy
Mazzy

Reputation: 14229

Append string to each element of a list in Terraform

My idea is to have elements of a list modified by appending to each of them a string. How could this be achieved? I haven't find any function that allow me to do that.

Upvotes: 22

Views: 16158

Answers (1)

Ignacio Millán
Ignacio Millán

Reputation: 8066

Have you tried formatlist()?

For example:

my_list_var = ["a", "b", "c"]
my_new_list = formatlist("%s-foo", var.mylist)

my_new_list will be:

["a-foo", "b-foo", "c-foo"]

Yo can also pass another list of the same length as parameter to append different strings to each element.

Upvotes: 44

Related Questions