DEV Community

loading...

delete an item from a list in terraform

drewmullen
Full-stack YAML engineer
・1 min read

I had a need to remove an expected item from a list recently while working with terraform. surprisingly, there is no native function to do that. The snippet below removes 2 from the list:

compact([for x in list(1 ,2 ,3 ,4 ,5) : x == 2 ? "" : x])

Try it for yourself!

echo 'compact([for x in list(1 ,2 ,3 ,4 ,5) : x == 2 ? "" : x])' | terraform console

Discussion (0)