github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/functions/setsubtract.html.md (about)

     1  ---
     2  layout: "functions"
     3  page_title: "setsubtract - Functions - Configuration Language"
     4  sidebar_current: "docs-funcs-collection-setsubtract"
     5  description: |-
     6    The setsubtract function returns a new set containing the elements
     7    from the first set that are not present in the second set
     8  ---
     9  
    10  # `setsubtract` Function
    11  
    12  -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and
    13  earlier, see
    14  [0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
    15  
    16  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
    17  [relative complement](https://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement) of the first set in the second set.
    18  
    19  ```hcl
    20  setsubtract(a, b)
    21  ```
    22  
    23  ## Examples
    24  
    25  ```
    26  > setsubtract(["a", "b", "c"], ["a", "c"])
    27  [
    28    "b",
    29  ]
    30  ```
    31  
    32  ### Set Difference (Symmetric Difference)
    33  
    34  ```
    35  > setunion(setsubtract(["a", "b", "c"], ["a", "c", "d"]), setsubtract(["a", "c", "d"], ["a", "b", "c"]))
    36  [
    37    "b",
    38    "d",
    39  ]
    40  ```
    41  
    42  
    43  ## Related Functions
    44  
    45  * [`setintersection`](./setintersection.html) computes the _intersection_ of multiple sets
    46  * [`setproduct`](./setproduct.html) computes the _Cartesian product_ of multiple
    47    sets.
    48  * [`setunion`](./setunion.html) computes the _union_ of
    49    multiple sets.