Today I Learnt FM
On , I learnt ...
How to remove elements from lists in Terraform

You can remove specific elements from a list or a set with this syntax


$ terraform console

> [for i in [1, 2, 3, 4, 5]: i if i != 3]
[
  1,
  2,
  4,
  5,
]
> toset([for i in toset([1, 2, 3, 4, 5]): i if i != 3])
toset([
  1,
  2,
  4,
  5,
])

There’s also a function that eliminates all the false-y values in a list.


> compact([1, 2, null, 3])
tolist([
  "1",
  "2",
  "3",
])