Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec_deployments: Add size parameter to data source #300

Merged
merged 3 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/300.txt
Original file line number Diff line number Diff line change
@@ -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.
```
3 changes: 3 additions & 0 deletions docs/data-sources/ec_deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ data "ec_deployments" "example" {
name_prefix = "test"
deployment_template_id = "azure-compute-optimized"

size = 200

tags = {
"foo" = "bar"
}
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion ec/ecdatasource/deploymentsdatasource/expanders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
50 changes: 50 additions & 0 deletions ec/ecdatasource/deploymentsdatasource/expanders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions ec/ecdatasource/deploymentsdatasource/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down