Terraform

# setintersection function reference

This topic provides reference information about the `setintersection`

function,
which computes the intersection of the specified sets.

## Introduction

The `setintersection`

function takes multiple sets and produces a single set
containing only the elements that all of the given sets have in common.
In other words, `setintersection`

computes the intersection of the sets.
Refer to Wikipedia's Intersection (set
theory) article
for a mathematical explanantion of set theory intersection.

## Syntax

Use the `setintersection`

function with the following syntax:

```
setintersection(sets...)
```

Replace `sets...`

with a comma-delimited list of sets such as `["a","b"], ["a","c","g"]`

. The elements of
the different sets do not have to be the same type.

The `setintersection`

result is an unordered set.

## Example use cases

This example passes in sets of strings and returns a set with one element.

```
> setintersection(["a", "b"], ["b", "c"], ["b", "d"])
[
"b",
]
```

This example passes in number sets of different sizes and returns a set with two elements.

```
> setintersection([3,3.3,4], [4,3.3,65,99], [4.0,3.3])
toset([
3.3,
4,
])
```

This examples pass in sets of different lengths and element types. The result is a set of two string elements.

```
> setintersection(["bob","jane",3], ["jane",3,"ajax",10], ["3","jane",26,"nomad"])
toset([
"3",
"jane",
])
```

## Related Functions

`contains`

tests whether a given list or set contains a given element value.`setproduct`

computes the*Cartesian product*of multiple sets.`setsubtract`

computes the*relative complement*of two sets`setunion`

computes the*union*of multiple sets.