You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/speakeasy-reference/extensions.mdx
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,8 @@ x-speakeasy-extension-rewrite:
81
81
{ extension: "x-speakeasy-type-override", description: "Allows the conversion of an attribute to a JSON string, accommodating dynamic structures in Terraform configurations." },
82
82
{ extension: "x-speakeasy-wrapped-attribute", description: "Enables additional API operation data to be placed under a specifically named attribute." },
83
83
{ extension: "x-speakeasy-xor-with", description: "Indicate mutually exclusive properties to prevent incompatible combinations in Terraform configurations." },
84
-
{ extension: "x-speakeasy-match", description: "Adjusts an API parameter name to align with a Terraform state property." }
84
+
{ extension: "x-speakeasy-match", description: "Adjusts an API parameter name to align with a Terraform state property." },
85
+
{ extension: "x-speakeasy-response-filter", description: "Enable client-side filtering of list API responses in data resources by marking response properties that Terraform users can filter on." }
Copy file name to clipboardExpand all lines: docs/terraform/customize-terraform/property-customization.mdx
+96Lines changed: 96 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -328,3 +328,99 @@ components:
328
328
should updates to attributes happen outside of Terraform changes. Please only
329
329
apply this when necessary.
330
330
</Callout>
331
+
332
+
## Filter Data Resource Results by Response Values
333
+
334
+
Some list API endpoints do not support server-side filtering. The `x-speakeasy-response-filter` extension enables client-side filtering of list API responses in [data resources](https://developer.hashicorp.com/terraform/language/data-sources), allowing Terraform users to narrow results by matching property values.
335
+
336
+
When applied to a response property, the generated data resource schema promotes that property to an optional, configurable attribute. If a user provides a value for a filter attribute, the generated provider filters the API response array on the client side, returning only items where the property matches the configured value.
337
+
338
+
<Callout title="Info" type="info">
339
+
This extension only applies to data resources that read from list API
340
+
endpoints returning arrays. Only top-level primitive fields (`string`,
341
+
`number`, `boolean`, `integer`) are supported as filter properties.
342
+
</Callout>
343
+
344
+
### Basic usage
345
+
346
+
Mark response properties with `x-speakeasy-response-filter: true` to make them available as filter attributes in the data resource:
347
+
348
+
```yaml
349
+
components:
350
+
schemas:
351
+
Pet:
352
+
x-speakeasy-entity: Pets
353
+
type: object
354
+
properties:
355
+
name:
356
+
type: string
357
+
x-speakeasy-response-filter: true
358
+
species:
359
+
type: string
360
+
x-speakeasy-response-filter: true
361
+
id:
362
+
type: integer
363
+
age:
364
+
type: integer
365
+
```
366
+
367
+
With the corresponding list operation:
368
+
369
+
```yaml
370
+
paths:
371
+
/pets:
372
+
get:
373
+
summary: List all pets
374
+
x-speakeasy-entity-operation: Pets#read
375
+
responses:
376
+
"200":
377
+
description: OK
378
+
content:
379
+
application/json:
380
+
schema:
381
+
type: array
382
+
items:
383
+
$ref: "#/components/schemas/Pet"
384
+
```
385
+
386
+
Terraform users can then filter the data resource results:
387
+
388
+
```hcl
389
+
data "example_pets" "dogs" {
390
+
name = "Buddy"
391
+
species = "dog"
392
+
}
393
+
```
394
+
395
+
The generated provider fetches all pets from the API and returns only items where `name` equals `"Buddy"` and `species` equals `"dog"`.
396
+
397
+
### Array response wrapping
398
+
399
+
For APIs where the response is wrapped in an object, the extension works with the array items. Filter fields are automatically hoisted from the array item level to the data resource root for a flat configuration experience:
400
+
401
+
```yaml
402
+
components:
403
+
schemas:
404
+
PetList:
405
+
x-speakeasy-entity: Pets
406
+
type: object
407
+
properties:
408
+
data:
409
+
type: array
410
+
items:
411
+
type: object
412
+
properties:
413
+
name:
414
+
type: string
415
+
x-speakeasy-response-filter: true
416
+
id:
417
+
type: integer
418
+
```
419
+
420
+
The Terraform configuration remains flat regardless of the API response structure:
0 commit comments