mirror of https://github.com/hashicorp/terraform
lang: add setsubtract function (#23424)
* add setdifference and setsubtract functions and docs * remove setdifference as it is not implemented correct in underlying lib * Update setintersection.html.md * Update setproduct.html.md * Update setunion.html.mdpull/24048/head
parent
b4f21b6044
commit
25bfe7337b
@ -0,0 +1,49 @@
|
||||
---
|
||||
layout: "functions"
|
||||
page_title: "setsubtract - Functions - Configuration Language"
|
||||
sidebar_current: "docs-funcs-collection-setsubtract"
|
||||
description: |-
|
||||
The setsubtract function returns a new set containing the elements
|
||||
from the first set that are not present in the second set
|
||||
---
|
||||
|
||||
# `setsubtract` Function
|
||||
|
||||
-> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
|
||||
earlier, see
|
||||
[0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
|
||||
|
||||
The `setsubtract` function returns a new set containing the elements from the first set that are not present in the second set. In other words, it computes the
|
||||
[relative complement](https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement) of the first set in the second set.
|
||||
|
||||
```hcl
|
||||
setsubtract(a, b)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
> setsubtract(["a", "b", "c"], ["a", "c"])
|
||||
[
|
||||
"b",
|
||||
]
|
||||
```
|
||||
|
||||
### Set Difference (Symmetric Difference)
|
||||
|
||||
```
|
||||
> setunion(setsubtract(["a", "b", "c"], ["a", "c", "d"]), setsubtract(["a", "c", "d"], ["a", "b", "c"]))
|
||||
[
|
||||
"b",
|
||||
"d",
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
## Related Functions
|
||||
|
||||
* [`setintersection`](./setintersection.html) computes the _intersection_ of multiple sets
|
||||
* [`setproduct`](./setproduct.html) computes the _Cartesian product_ of multiple
|
||||
sets.
|
||||
* [`setunion`](./setunion.html) computes the _union_ of
|
||||
multiple sets.
|
||||
Loading…
Reference in new issue