lang/funcs: remove sethaselement function and documentation (#21164)
`contains` and `sethaselement` are effectively the same function, and `contains` works with `sets` thanks to automatic HCL conversion.
This commit is contained in:
parent
d2bc9ca406
commit
b1d0b1383f
|
@ -120,7 +120,7 @@ var LengthFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// CoalesceFunc contructs a function that takes any number of arguments and
|
||||
// CoalesceFunc constructs a function that takes any number of arguments and
|
||||
// returns the first one that isn't empty. This function was copied from go-cty
|
||||
// stdlib and modified so that it returns the first *non-empty* non-null element
|
||||
// from a sequence, instead of merely the first non-null.
|
||||
|
@ -164,7 +164,7 @@ var CoalesceFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// CoalesceListFunc contructs a function that takes any number of list arguments
|
||||
// CoalesceListFunc constructs a function that takes any number of list arguments
|
||||
// and returns the first one that isn't empty.
|
||||
var CoalesceListFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{},
|
||||
|
@ -224,7 +224,7 @@ var CoalesceListFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// CompactFunc contructs a function that takes a list of strings and returns a new list
|
||||
// CompactFunc constructs a function that takes a list of strings and returns a new list
|
||||
// with any empty string elements removed.
|
||||
var CompactFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -260,10 +260,8 @@ var CompactFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// ContainsFunc contructs a function that determines whether a given list
|
||||
// contains a given single value as one of its elements.
|
||||
//
|
||||
// ContainsFunc also works on sets, as HCL automatically converts sets to lists.
|
||||
// ContainsFunc constructs a function that determines whether a given list or
|
||||
// set contains a given single value as one of its elements.
|
||||
var ContainsFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
{
|
||||
|
@ -293,7 +291,7 @@ var ContainsFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// IndexFunc contructs a function that finds the element index for a given value in a list.
|
||||
// IndexFunc constructs a function that finds the element index for a given value in a list.
|
||||
var IndexFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
{
|
||||
|
@ -337,7 +335,7 @@ var IndexFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// DistinctFunc contructs a function that takes a list and returns a new list
|
||||
// DistinctFunc constructs a function that takes a list and returns a new list
|
||||
// with any duplicate elements removed.
|
||||
var DistinctFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -369,7 +367,7 @@ var DistinctFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// ChunklistFunc contructs a function that splits a single list into fixed-size chunks,
|
||||
// ChunklistFunc constructs a function that splits a single list into fixed-size chunks,
|
||||
// returning a list of lists.
|
||||
var ChunklistFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -430,7 +428,7 @@ var ChunklistFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// FlattenFunc contructs a function that takes a list and replaces any elements
|
||||
// FlattenFunc constructs a function that takes a list and replaces any elements
|
||||
// that are lists with a flattened sequence of the list contents.
|
||||
var FlattenFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -499,7 +497,7 @@ func flattener(flattenList cty.Value) ([]cty.Value, bool) {
|
|||
return out, true
|
||||
}
|
||||
|
||||
// KeysFunc contructs a function that takes a map and returns a sorted list of the map keys.
|
||||
// KeysFunc constructs a function that takes a map and returns a sorted list of the map keys.
|
||||
var KeysFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
{
|
||||
|
@ -569,7 +567,7 @@ var KeysFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// ListFunc contructs a function that takes an arbitrary number of arguments
|
||||
// ListFunc constructs a function that takes an arbitrary number of arguments
|
||||
// and returns a list containing those values in the same order.
|
||||
//
|
||||
// This function is deprecated in Terraform v0.12
|
||||
|
@ -613,7 +611,7 @@ var ListFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// LookupFunc contructs a function that performs dynamic lookups of map types.
|
||||
// LookupFunc constructs a function that performs dynamic lookups of map types.
|
||||
var LookupFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
{
|
||||
|
@ -707,7 +705,7 @@ var LookupFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// MapFunc contructs a function that takes an even number of arguments and
|
||||
// MapFunc constructs a function that takes an even number of arguments and
|
||||
// returns a map whose elements are constructed from consecutive pairs of arguments.
|
||||
//
|
||||
// This function is deprecated in Terraform v0.12
|
||||
|
@ -780,7 +778,7 @@ var MapFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// MatchkeysFunc contructs a function that constructs a new list by taking a
|
||||
// MatchkeysFunc constructs a function that constructs a new list by taking a
|
||||
// subset of elements from one list whose indexes match the corresponding
|
||||
// indexes of values in another list.
|
||||
var MatchkeysFunc = function.New(&function.Spec{
|
||||
|
@ -858,7 +856,7 @@ var MatchkeysFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// MergeFunc contructs a function that takes an arbitrary number of maps and
|
||||
// MergeFunc constructs a function that takes an arbitrary number of maps and
|
||||
// returns a single map that contains a merged set of elements from all of the maps.
|
||||
//
|
||||
// If more than one given map defines the same key then the one that is later in
|
||||
|
@ -1057,7 +1055,7 @@ var SetProductFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// SliceFunc contructs a function that extracts some consecutive elements
|
||||
// SliceFunc constructs a function that extracts some consecutive elements
|
||||
// from within a list.
|
||||
var SliceFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -1141,6 +1139,7 @@ func sliceIndexes(args []cty.Value, max int) (int, int, error) {
|
|||
}
|
||||
|
||||
// TransposeFunc contructs a function that takes a map of lists of strings and
|
||||
// TransposeFunc constructs a function that takes a map of lists of strings and
|
||||
// swaps the keys and values to produce a new map of lists of strings.
|
||||
var TransposeFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -1190,7 +1189,7 @@ var TransposeFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// ValuesFunc contructs a function that returns a list of the map values,
|
||||
// ValuesFunc constructs a function that returns a list of the map values,
|
||||
// in the order of the sorted keys.
|
||||
var ValuesFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
@ -1247,7 +1246,7 @@ var ValuesFunc = function.New(&function.Spec{
|
|||
},
|
||||
})
|
||||
|
||||
// ZipmapFunc contructs a function that constructs a map from a list of keys
|
||||
// ZipmapFunc constructs a function that constructs a map from a list of keys
|
||||
// and a corresponding list of values.
|
||||
var ZipmapFunc = function.New(&function.Spec{
|
||||
Params: []function.Parameter{
|
||||
|
|
|
@ -88,7 +88,6 @@ func (s *Scope) Functions() map[string]function.Function {
|
|||
"replace": funcs.ReplaceFunc,
|
||||
"reverse": funcs.ReverseFunc,
|
||||
"rsadecrypt": funcs.RsaDecryptFunc,
|
||||
"sethaselement": stdlib.SetHasElementFunc,
|
||||
"setintersection": stdlib.SetIntersectionFunc,
|
||||
"setproduct": funcs.SetProductFunc,
|
||||
"setunion": stdlib.SetUnionFunc,
|
||||
|
|
|
@ -527,13 +527,6 @@ func TestFunctions(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
"sethaselement": {
|
||||
{
|
||||
`sethaselement(["a", "b"], "b")`,
|
||||
cty.BoolVal(true),
|
||||
},
|
||||
},
|
||||
|
||||
"setintersection": {
|
||||
{
|
||||
`setintersection(["a", "b"], ["b", "c"], ["b", "d"])`,
|
||||
|
|
|
@ -3,7 +3,7 @@ layout: "functions"
|
|||
page_title: "contains - Functions - Configuration Language"
|
||||
sidebar_current: "docs-funcs-collection-contains"
|
||||
description: |-
|
||||
The contains function determines whether a list contains a given value.
|
||||
The contains function determines whether a list or set contains a given value.
|
||||
---
|
||||
|
||||
# `contains` Function
|
||||
|
@ -12,7 +12,7 @@ description: |-
|
|||
earlier, see
|
||||
[0.11 Configuration Language: Interpolation Syntax](../../configuration-0-11/interpolation.html).
|
||||
|
||||
`contains` determines whether a given list contains a given single value
|
||||
`contains` determines whether a given list or set contains a given single value
|
||||
as one of its elements.
|
||||
|
||||
```hcl
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
---
|
||||
layout: "functions"
|
||||
page_title: "sethaselement - Functions - Configuration Language"
|
||||
sidebar_current: "docs-funcs-collection-sethaselement"
|
||||
description: |-
|
||||
The sethaselement function tests whether a given value is in a given set.
|
||||
---
|
||||
|
||||
# `sethaselement` 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 `sethaselement` function tests whether a given value is in a given set.
|
||||
|
||||
```hcl
|
||||
sethaselement(set, value)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
> sethaselement(["a", "b"], "b")
|
||||
true
|
||||
> sethaselement(["a", "b"], "c")
|
||||
false
|
||||
```
|
||||
|
||||
## 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.
|
|
@ -36,7 +36,7 @@ the ordering of the given elements is not preserved.
|
|||
|
||||
## Related Functions
|
||||
|
||||
* [`sethaselement`](./sethaselement.html) tests whether a given set contains
|
||||
* [`contains`](./contains.html) tests whether a given list or set contains
|
||||
a given element value.
|
||||
* [`setproduct`](./setproduct.html) computes the _cartesian product_ of multiple
|
||||
sets.
|
||||
|
|
|
@ -120,7 +120,7 @@ elements all have a consistent type:
|
|||
|
||||
## Related Functions
|
||||
|
||||
* [`sethaselement`](./sethaselement.html) tests whether a given set contains
|
||||
* [`contains`](./contains.html) tests whether a given list or set contains
|
||||
a given element value.
|
||||
* [`setintersection`](./setintersection.html) computes the _intersection_ of
|
||||
multiple sets.
|
||||
|
|
|
@ -39,7 +39,7 @@ the ordering of the given elements is not preserved.
|
|||
|
||||
## Related Functions
|
||||
|
||||
* [`sethaselement`](./sethaselement.html) tests whether a given set contains
|
||||
* [`contains`](./contains.html) tests whether a given list or set contains
|
||||
a given element value.
|
||||
* [`setintersection`](./setintersection.html) computes the _intersection_ of
|
||||
multiple sets.
|
||||
|
|
|
@ -186,10 +186,6 @@
|
|||
<a href="/docs/configuration/functions/reverse.html">reverse</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="/docs/configuration/functions/sethaselement.html">sethaselement</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="/docs/configuration/functions/setintersection.html">setintersection</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue