From 9e945d7010eef7ed6bc51f5387e82622df5ed8ea Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Wed, 21 Apr 2021 14:03:37 +0500 Subject: [PATCH 1/3] ec_deployments: Add size parameter to data source Adds a new `size` integer parameter to the `ec_deployments` data source which allows users to specify a maximum number of deployments to be returned. The API defaults to 10 and the provider defaults to `100`. Signed-off-by: Marc Lopez --- docs/data-sources/ec_deployments.md | 3 ++ .../deploymentsdatasource/expanders.go | 4 +- .../deploymentsdatasource/expanders_test.go | 50 +++++++++++++++++++ .../deploymentsdatasource/schema.go | 7 +++ examples/deployment/deployment.tf | 3 +- 5 files changed, 65 insertions(+), 2 deletions(-) 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, diff --git a/examples/deployment/deployment.tf b/examples/deployment/deployment.tf index 1b492388f..a8fd9cc62 100644 --- a/examples/deployment/deployment.tf +++ b/examples/deployment/deployment.tf @@ -22,7 +22,8 @@ data "ec_stack" "latest" { # Create an Elastic Cloud deployment resource "ec_deployment" "example_minimal" { # Optional name. - name = "my_example_deployment" + name = "my_example_deployment" + alias = "some" # Mandatory fields region = "us-east-1" From d2cc4192ac18045c958c61dcfd7a4b11fb548c96 Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Wed, 21 Apr 2021 14:07:23 +0500 Subject: [PATCH 2/3] Add changelog entry Signed-off-by: Marc Lopez --- .changelog/300.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/300.txt 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 From 5676f2efa34defc8011249512f670de6a056488e Mon Sep 17 00:00:00 2001 From: Marc Lopez Date: Wed, 21 Apr 2021 15:06:11 +0500 Subject: [PATCH 3/3] Remove examples change Signed-off-by: Marc Lopez --- examples/deployment/deployment.tf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/deployment/deployment.tf b/examples/deployment/deployment.tf index a8fd9cc62..1b492388f 100644 --- a/examples/deployment/deployment.tf +++ b/examples/deployment/deployment.tf @@ -22,8 +22,7 @@ data "ec_stack" "latest" { # Create an Elastic Cloud deployment resource "ec_deployment" "example_minimal" { # Optional name. - name = "my_example_deployment" - alias = "some" + name = "my_example_deployment" # Mandatory fields region = "us-east-1"