I have a list in terraform for example
["a","b"]
I want the list to be expanded like below for a use case.
["a","a","b","b"]
If list has just one value. It should just duplicate the value.
Please suggest.
assuming you just want to duplicate every item on the list and preserve the order you could iterate over the list making new lists that contain the item twice and then flatten all the lists back to a single list
locals {
original = ["a", "b"]
duplicated = flatten([for item in local.original: [item, item]])
}
output "show" {
value = local.duplicated
}
OUTPUT
Outputs:
show = [
"a",
"a",
"b",
"b",
]