Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get intersection of two lists in terraform?

Tags:

terraform

I have two lists in terraform and want to get the intersection of these lists.

For example,

list1 = ["a", "b", "c"]
lists2 = ["b", "c", "d"]

I am looking to get output as ["b", "c"] using built-in terraform functions.

like image 527
pradeep Avatar asked Nov 02 '25 05:11

pradeep


1 Answers

You are looking for something like this

 output my_intersection {
   value = setintersection( toset(var.list1), toset(var.list2) )
 }
like image 92
Roman Gherta Avatar answered Nov 04 '25 21:11

Roman Gherta