Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append string to each element of a list in Terraform

Tags:

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.

like image 822
Mazzy Avatar asked Aug 13 '18 12:08

Mazzy


1 Answers

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.

like image 129
Ignacio Millán Avatar answered Nov 01 '22 20:11

Ignacio Millán