-
Notifications
You must be signed in to change notification settings - Fork 211
feat: Add num_partitions field in mongodbatlas_search_index #3982
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
base: master
Are you sure you want to change the base?
Changes from all commits
d540b4c
636bf20
94323db
aee15fe
e7b8490
b12949e
a1f2219
b251b43
bf5407c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ```release-note:enhancement | ||
| resource/mongodbatlas_search_index: Adds `num_partitions` attribute | ||
| ``` | ||
|
|
||
| ```release-note:enhancement | ||
| data-source/mongodbatlas_search_index: Adds `num_partitions` attribute | ||
| ``` | ||
|
|
||
| ```release-note:enhancement | ||
| data-source/mongodbatlas_search_indexes: Adds `num_partitions` attribute | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,5 +52,6 @@ data "mongodbatlas_search_indexes" "test" { | |
| * `type_sets` - Set of type set definitions (when present). Each item includes: | ||
| * `name` - Type set name. | ||
| * `types` - JSON array string describing the types for the set. | ||
| * `num_partitions` - Number of index partitions, returns 0 if not set in the resource | ||
|
||
|
|
||
| For more information see: [MongoDB Atlas API Reference.](https://docs.atlas.mongodb.com/atlas-search/) - [and MongoDB Atlas API - Search](https://docs.atlas.mongodb.com/reference/api/atlas-search/) Documentation for more information. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -237,6 +237,8 @@ EOF | |
| EOF | ||
| ``` | ||
|
|
||
| * `num_partitions` - (Optional) Number of index partitions. Allowed values are [1, 2, 4]. Default value is 1. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qq: can it be used in both search and vectorSearch types?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you! added the a test for vectorSearch as well. |
||
|
|
||
| ## Attributes Reference | ||
|
|
||
| In addition to all arguments above, the following attributes are exported: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,10 @@ func returnSearchIndexDSSchema() map[string]*schema.Schema { | |
| }, | ||
| }, | ||
| }, | ||
| "num_partitions": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you confirm that if num_partitions is not used when creating the resource, we'll get null in the data sources (instead of default 1)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We receive an integer pointer as nil. Since SDKv2 does not natively handle nil values, and our num_partitions field is of type integer, the field will default to an undefined integer value, equal to 0. |
||
| }, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -223,6 +227,10 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour | |
| return diag.Errorf("error setting `stored_source` for search index (%s): %s", d.Id(), err) | ||
| } | ||
|
|
||
| if err := d.Set("num_partitions", searchIndex.LatestDefinition.NumPartitions); err != nil { | ||
| return diag.Errorf("error setting `num_partitions` for search index (%s): %s", d.Id(), err) | ||
| } | ||
|
|
||
| d.SetId(conversion.EncodeStateID(map[string]string{ | ||
| "project_id": projectID.(string), | ||
| "cluster_name": clusterName.(string), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |||||
| "context" | ||||||
| "fmt" | ||||||
| "regexp" | ||||||
| "strconv" | ||||||
| "testing" | ||||||
|
|
||||||
| "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||||||
|
|
@@ -192,6 +193,57 @@ func TestAccSearchIndex_withVector(t *testing.T) { | |||||
| resource.ParallelTest(t, *basicVectorTestCase(t)) | ||||||
| } | ||||||
|
|
||||||
| func TestAccSearchIndex_withNumPartitions(t *testing.T) { | ||||||
| var ( | ||||||
| projectID, clusterName = acc.ClusterNameExecution(t, true) | ||||||
| indexName = acc.RandomName() | ||||||
| ) | ||||||
| resource.Test(t, resource.TestCase{ | ||||||
| PreCheck: func() { acc.PreCheckBasic(t) }, | ||||||
| ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||||||
| CheckDestroy: acc.CheckDestroySearchIndex, | ||||||
| Steps: []resource.TestStep{ | ||||||
| { | ||||||
| Config: configSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| Check: checkSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| }, | ||||||
| { | ||||||
| Config: configSearchWithNumPartitions(projectID, indexName, clusterName, conversion.IntPtr(2)), | ||||||
| Check: checkSearchWithNumPartitions(projectID, indexName, clusterName, conversion.IntPtr(2)), | ||||||
| }, | ||||||
| { | ||||||
| Config: configSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| Check: checkSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
| } | ||||||
|
|
||||||
| func TestAccVectorSearchIndex_withNumPartitions(t *testing.T) { | ||||||
| var ( | ||||||
| projectID, clusterName = acc.ClusterNameExecution(t, true) | ||||||
| indexName = acc.RandomName() | ||||||
| ) | ||||||
| resource.Test(t, resource.TestCase{ | ||||||
| PreCheck: func() { acc.PreCheckBasic(t) }, | ||||||
| ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||||||
| CheckDestroy: acc.CheckDestroySearchIndex, | ||||||
| Steps: []resource.TestStep{ | ||||||
| { | ||||||
| Config: configVectorSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| Check: checkVectorSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| }, | ||||||
| { | ||||||
| Config: configVectorSearchWithNumPartitions(projectID, indexName, clusterName, conversion.IntPtr(2)), | ||||||
| Check: checkVectorSearchWithNumPartitions(projectID, indexName, clusterName, conversion.IntPtr(2)), | ||||||
| }, | ||||||
| { | ||||||
| Config: configVectorSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| Check: checkVectorSearchWithNumPartitions(projectID, indexName, clusterName, nil), | ||||||
| }, | ||||||
| }, | ||||||
| }) | ||||||
| } | ||||||
| func basicTestCase(tb testing.TB) *resource.TestCase { | ||||||
| tb.Helper() | ||||||
| var ( | ||||||
|
|
@@ -372,7 +424,7 @@ func configBasic(projectID, clusterName, indexName, indexType, storedSource stri | |||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, searchAnalyzer, extra) | ||||||
| } | ||||||
|
|
@@ -409,7 +461,7 @@ func configWithMapping(projectID, indexName, clusterName string) string { | |||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, searchAnalyzer, analyzersTF, mappingsFieldsTF) | ||||||
| } | ||||||
|
|
@@ -451,7 +503,7 @@ func configWithSynonyms(projectID, indexName, clusterName string, has bool) stri | |||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, searchAnalyzer, synonymsStr) | ||||||
| } | ||||||
|
|
@@ -489,7 +541,7 @@ func configAdditional(projectID, indexName, clusterName, additional string) stri | |||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, searchAnalyzer, additional) | ||||||
| } | ||||||
|
|
@@ -533,11 +585,117 @@ func configVector(projectID, indexName, clusterName string) string { | |||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, fieldsJSON) | ||||||
| } | ||||||
|
|
||||||
| func configVectorSearchWithNumPartitions(projectID, indexName, clusterName string, numPartitions *int) string { | ||||||
| var numPartitionsLine string | ||||||
| hasNumPartitions := numPartitions != nil | ||||||
| if hasNumPartitions { | ||||||
| numPartitionsLine = fmt.Sprintf("num_partitions = %d", *numPartitions) | ||||||
| } | ||||||
| return fmt.Sprintf(` | ||||||
|
|
||||||
| resource "mongodbatlas_search_deployment" "test" { | ||||||
| cluster_name = %[1]q | ||||||
| project_id = %[2]q | ||||||
| specs = [ | ||||||
| { | ||||||
| instance_size = "S20_HIGHCPU_NVME" | ||||||
| node_count = 2 | ||||||
| } | ||||||
| ] | ||||||
| } | ||||||
|
|
||||||
| resource "mongodbatlas_search_index" "test" { | ||||||
| cluster_name = %[1]q | ||||||
| project_id = %[2]q | ||||||
| name = %[3]q | ||||||
| database = %[4]q | ||||||
| collection_name = %[5]q | ||||||
|
|
||||||
| type = "vectorSearch" | ||||||
| %[6]s | ||||||
| fields = <<-EOF | ||||||
| %[7]s | ||||||
| EOF | ||||||
|
|
||||||
| depends_on = [mongodbatlas_search_deployment.test] | ||||||
| } | ||||||
|
|
||||||
| data "mongodbatlas_search_index" "data_index" { | ||||||
| cluster_name = mongodbatlas_search_index.test.cluster_name | ||||||
| project_id = mongodbatlas_search_index.test.project_id | ||||||
| index_id = mongodbatlas_search_index.test.index_id | ||||||
| } | ||||||
| `, clusterName, projectID, indexName, database, collection, numPartitionsLine, fieldsJSON) | ||||||
| } | ||||||
| func configSearchWithNumPartitions(projectID, indexName, clusterName string, numPartitions *int) string { | ||||||
| var numPartitionsLine string | ||||||
| hasNumPartitions := numPartitions != nil | ||||||
| if hasNumPartitions { | ||||||
| numPartitionsLine = fmt.Sprintf("num_partitions = %d", *numPartitions) | ||||||
| } | ||||||
| return fmt.Sprintf(` | ||||||
|
|
||||||
| resource "mongodbatlas_search_deployment" "test" { | ||||||
| cluster_name = %[1]q | ||||||
| project_id = %[2]q | ||||||
| specs = [ | ||||||
| { | ||||||
| instance_size = "S20_HIGHCPU_NVME" | ||||||
| node_count = 2 | ||||||
| } | ||||||
| ] | ||||||
| } | ||||||
|
|
||||||
| resource "mongodbatlas_search_index" "test" { | ||||||
| cluster_name = %[1]q | ||||||
| project_id = %[2]q | ||||||
| name = %[3]q | ||||||
| database = %[4]q | ||||||
| collection_name = %[5]q | ||||||
| analyzer = "lucene.standard" | ||||||
| search_analyzer = "lucene.standard" | ||||||
| mappings_dynamic = true | ||||||
| type = "search" | ||||||
| %[6]s | ||||||
|
|
||||||
| depends_on = [mongodbatlas_search_deployment.test] | ||||||
|
||||||
| depends_on = [mongodbatlas_search_deployment.test] | |
| depends_on = [mongodbatlas_search_deployment.test] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states 'returns 0 if not set in the resource', but this phrasing is unclear as this is a data source, not a resource. Consider rephrasing to 'returns 0 if not configured' or 'returns 0 when not set' for clarity.