diff --git a/.changelog/300.txt b/.changelog/300.txt new file mode 100644 index 000000000..fcc3c7c96 --- /dev/null +++ b/.changelog/300.txt @@ -0,0 +1,3 @@ +```release-note:feature +datasource/ec_deployment: Add a new size parameter to allow modifying the default size of `10` in the number of deployments returned by the search request. +``` \ No newline at end of file diff --git a/docs/data-sources/ec_deployments.md b/docs/data-sources/ec_deployments.md index 22739a3cc..2f563b5d1 100644 --- a/docs/data-sources/ec_deployments.md +++ b/docs/data-sources/ec_deployments.md @@ -15,6 +15,8 @@ data "ec_deployments" "example" { name_prefix = "test" deployment_template_id = "azure-compute-optimized" + size = 200 + tags = { "foo" = "bar" } @@ -41,6 +43,7 @@ data "ec_deployments" "example" { * `name_prefix` - Prefix that one or several deployment names have in common. * `deployment_template_id` - ID of the deployment template used to create the deployment. +* `size` - The maximum number of deployments to return. Defaults to `100`. * `tags` - Key value map of arbitrary string tags for the deployment. * `healthy` - Overall health status of the deployment. * `elasticsearch` - Filter by Elasticsearch resource kind status or configuration. diff --git a/ec/ecdatasource/deploymentsdatasource/expanders.go b/ec/ecdatasource/deploymentsdatasource/expanders.go index 5cfc3eb3f..11746ea3c 100644 --- a/ec/ecdatasource/deploymentsdatasource/expanders.go +++ b/ec/ecdatasource/deploymentsdatasource/expanders.go @@ -91,7 +91,9 @@ func expandFilters(d *schema.ResourceData) (*models.SearchRequest, error) { queries = append(queries, req...) } - var searchReq models.SearchRequest + searchReq := models.SearchRequest{ + Size: int32(d.Get("size").(int)), + } if len(queries) > 0 { searchReq.Query = &models.QueryContainer{ diff --git a/ec/ecdatasource/deploymentsdatasource/expanders_test.go b/ec/ecdatasource/deploymentsdatasource/expanders_test.go index 3636f9213..757977b31 100644 --- a/ec/ecdatasource/deploymentsdatasource/expanders_test.go +++ b/ec/ecdatasource/deploymentsdatasource/expanders_test.go @@ -54,6 +54,56 @@ func Test_expandFilters(t *testing.T) { name: "parses the data source", args: args{d: deploymentsDS}, want: &models.SearchRequest{ + Size: 100, + Query: &models.QueryContainer{ + Bool: &models.BoolQuery{ + Filter: []*models.QueryContainer{ + { + Bool: &models.BoolQuery{ + Must: newTestQuery(), + }, + }, + }, + }, + }, + }, + }, + { + name: "parses the data source with a different size", + args: args{d: util.NewResourceData(t, util.ResDataParams{ + ID: "myID", + Schema: newSchema(), + State: map[string]interface{}{ + "name_prefix": "test", + "healthy": "true", + "size": 200, + "tags": map[string]interface{}{ + "foo": "bar", + }, + "elasticsearch": []interface{}{ + map[string]interface{}{ + "version": "7.9.1", + }, + }, + "kibana": []interface{}{ + map[string]interface{}{ + "status": "started", + }, + }, + "apm": []interface{}{ + map[string]interface{}{ + "healthy": "true", + }, + }, + "enterprise_search": []interface{}{ + map[string]interface{}{ + "healthy": "false", + }, + }, + }, + })}, + want: &models.SearchRequest{ + Size: 200, Query: &models.QueryContainer{ Bool: &models.BoolQuery{ Filter: []*models.QueryContainer{ diff --git a/ec/ecdatasource/deploymentsdatasource/schema.go b/ec/ecdatasource/deploymentsdatasource/schema.go index 4e029d349..fa9b888d0 100644 --- a/ec/ecdatasource/deploymentsdatasource/schema.go +++ b/ec/ecdatasource/deploymentsdatasource/schema.go @@ -40,6 +40,13 @@ func newSchema() map[string]*schema.Schema { Type: schema.TypeString, }, }, + "size": { + Type: schema.TypeInt, + Optional: true, + Default: 100, + }, + + // Computed "return_count": { Type: schema.TypeInt, Computed: true,