How to remove an empty string from a list in terraform?

You can use terraform compact() function to remove an empty string from a list. compact() takes a list of strings and returns a new list with any empty string elements removed.

Syntax: compact(list)

Example: