|  | 
|  | 1 | +### Data Sources Filtering | 
|  | 2 | + | 
|  | 3 | +Most data sources that return lists of resources now support filtering  | 
|  | 4 | +semantics. To employ a filter include this block in your data source  | 
|  | 5 | +definition: | 
|  | 6 | + | 
|  | 7 | +``` | 
|  | 8 | +filter { | 
|  | 9 | +	name = "" | 
|  | 10 | +	values = [""] | 
|  | 11 | +} | 
|  | 12 | +``` | 
|  | 13 | + | 
|  | 14 | +The `name` value corresponds to the property name to filter with  | 
|  | 15 | +and the `values` lists can contain one or more values filter with.  | 
|  | 16 | + | 
|  | 17 | +Multiple `values` work as an **OR** type filter. In the shape  | 
|  | 18 | +example below, the resulting data source would contain both VM  | 
|  | 19 | +shapes _Standard 1.1_ and _Standard 1.2_: | 
|  | 20 | +``` | 
|  | 21 | +data "oci_core_shape" "t" { | 
|  | 22 | +  ... | 
|  | 23 | +  filter { | 
|  | 24 | +    name = "name" | 
|  | 25 | +    values = ["VM.Standard1.1", "VM.Standard1.2"] | 
|  | 26 | +  } | 
|  | 27 | +} | 
|  | 28 | +``` | 
|  | 29 | + | 
|  | 30 | +Multiple filters blocks can be composed to form **AND** type comparisons  | 
|  | 31 | +as well. The example below will return a data source containing  | 
|  | 32 | +_running instances_ in the _first AD_ of a region: | 
|  | 33 | +``` | 
|  | 34 | +data "oci_core_instances" "s" { | 
|  | 35 | +	... | 
|  | 36 | +  filter { | 
|  | 37 | +    name = "availability_domain" | 
|  | 38 | +    values = ["\\w*-AD-1"] | 
|  | 39 | +    regex = true | 
|  | 40 | +  } | 
|  | 41 | +
 | 
|  | 42 | +  filter { | 
|  | 43 | +    name = "state" | 
|  | 44 | +    values = ["RUNNING"] | 
|  | 45 | +  } | 
|  | 46 | +} | 
|  | 47 | +         | 
|  | 48 | +``` | 
|  | 49 | + | 
|  | 50 | +As shown above, filters can also employ regular expressions. By setting | 
|  | 51 | +`regex = true`, each item in the `values` list will be treated as a  | 
|  | 52 | +regular expression. Note that backslashes in strings for regular | 
|  | 53 | +expression special characters need to be escaped with another slash, | 
|  | 54 | +shown above as the first `\` before `\w` in `"\\w*-AD-1"`. | 
|  | 55 | + | 
|  | 56 | +### Limitations | 
|  | 57 | +Currently filters can only target top level string attributes of a  | 
|  | 58 | +resource (or top level arrays of strings).  | 
|  | 59 | + | 
|  | 60 | +Support for other types (booleans) and drilling into properties of  | 
|  | 61 | +structured objects or lists of structured objects is not currently  | 
|  | 62 | +supported. If these properties are targeted no results will be  | 
|  | 63 | +returned from the datasource. | 
0 commit comments