-
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?
feat: Add num_partitions field in mongodbatlas_search_index #3982
Conversation
|
APIx bot: a message has been sent to Docs Slack channel |
QuiqueSanMongo
left a comment
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.
LGTM, just a small question
docs/data-sources/search_index.md
Outdated
| * `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` - (Optional) Number of index partitions. Allowed values are [1, 2, 4]. |
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.
Does the feature just allow 1, 2, and 4, or is this a typo?
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.
thank you! yess, link to the api definition in here. additionally, I've updated the definition with the default value:
Number of index partitions. Allowed values are [1, 2, 4]. Default value is 1.
|
I see that the PR is marked as |
|
@marcabreracast thank you! I have converted it back to draft until I address your feedback! |
|
@marcabreracast Thank you. I have updated the PR |
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.
Pull request overview
This PR adds support for the num_partitions field to the MongoDB Atlas search index resource and data sources in the Terraform provider. The field allows users to configure index partitioning (with allowed values of 1, 2, or 4) through Terraform.
Key changes:
- Added
num_partitionsfield to search index resource, data sources, and their schemas - Implemented create, read, and update logic for the new field
- Added comprehensive test coverage including create and update scenarios
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/service/searchindex/resource_search_index.go | Added num_partitions field to schema and implemented create/read/update logic |
| internal/service/searchindex/data_source_search_index.go | Added num_partitions as computed field in data source schema and read logic |
| internal/service/searchindex/data_source_search_indexes.go | Added num_partitions to flattened search indexes output |
| internal/service/searchindex/resource_search_index_test.go | Added test case for num_partitions with create and update scenarios |
| docs/resources/search_index.md | Documented num_partitions parameter with allowed values |
| docs/data-sources/search_index.md | Documented num_partitions attribute in data source |
| docs/data-sources/search_indexes.md | Documented num_partitions attribute in plural data source |
| .changelog/3982.txt | Added changelog entries for the enhancement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/data-sources/search_index.md
Outdated
| * `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. Allowed values are [1, 2, 4]. Default value is 1. |
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.
nit: for both datasource i think just "* num_partitions - Number of index partitions." is enough, allowed values and default value is more insteresting for the resource
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.
thank you! updated!
| EOF | ||
| ``` | ||
|
|
||
| * `num_partitions` - (Optional) Number of index partitions. Allowed values are [1, 2, 4]. Default value is 1. |
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.
qq: can it be used in both search and vectorSearch types?
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.
thank you! added the a test for vectorSearch as well.
| }, | ||
| "num_partitions": { | ||
| Type: schema.TypeInt, | ||
| Computed: true, |
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.
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)
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.
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.
QuiqueSanMongo
left a comment
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.
LGTM!
| resource.ParallelTest(t, *basicVectorTestCase(t)) | ||
| } | ||
| func TestAccSearchIndex_withNumPartitions(t *testing.T) { | ||
| resource.ParallelTest(t, *numPartitionsTestCase(t)) |
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.
in this case that we're not reusing the test (e.g. for acceptance and migration test), you can inline numPartitionsTestCase and just have the code in TestAccSearchIndex_withNumPartitions
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.
thank you! changed.
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: configSearchWithNumPartitions(projectID, indexName, clusterName, 2), | ||
| Check: checkSearchWithNumPartitions(projectID, indexName, clusterName, 2), |
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.
similar to what Leo mentioned in another comment, it would be nice to test the case of when we don't set the num_partitions, that in the resource the field is not set/nil, and in the data source it has the default value 1 (i assume the API returns the value even if not explitictly set)
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.
would also revise behaviour if attribute is initially defined and then removed
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.
I have added some more tests as you, Leo and Agustin suggested. However, since we are not able to handle the returned nil value (when not set), we process it as a 0 and that is why I assert based on that. Thank you!
oarbusi
left a comment
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.
LGTM, just one test case suggestion
marcabreracast
left a comment
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.
LGTM, thank you for addressing my suggestion. Agreed with Leo and Oriol on the test suggestions, feel free to apply those.
.changelog/3982.txt
Outdated
| @@ -0,0 +1,11 @@ | |||
| ```release-note:enhancement | |||
| resource/mongodbatlas_search_index: Adds the `num_partitions` attribute | |||
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.
| resource/mongodbatlas_search_index: Adds the `num_partitions` attribute | |
| resource/mongodbatlas_search_index: Adds `num_partitions` attribute |
nit: Just to stay consistent with other entries (applies to the 3 entries) https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/contributing/changelog-process.md#resource-and-provider-enhancements
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.
thank you! changed.
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.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var ret int | ||
| checks = append(checks, | ||
| resource.TestCheckResourceAttr(resourceName, "num_partitions", strconv.Itoa(ret)), | ||
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", strconv.Itoa(ret)), | ||
| ) |
Copilot
AI
Dec 16, 2025
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 variable ret is declared but never assigned a value, making its purpose unclear. Since it will always be 0 (the zero value for int), it would be clearer to either use '0' directly in the string, use strconv.Itoa(0), or rename the variable to something like defaultNumPartitions with an explicit assignment to 0.
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.
I tried to replicate the actual behavior of the resource/data source. Specifically, the situation where an integer pointer is received as nil. Since SDKv2 does not natively handle nil values, and our num_partitions field is of type integer, in such cases, the field will default to an undefined integer value.
To simulate this behavior in Go, even when we receive a nil, it is processed as zero. Here’s the code snippet that demonstrates this.
if o == nil || IsNil(o.NumPartitions)
{ var ret int return ret }
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.
I think that the point here is that var ret int is not an undefined int value, its always 0.
So we can directly check for "0" which is what we expect.
The go int zero value will never change, but in the hypothetical case it did, we want to make sure there is no regression in the datasource: we expect a 0.
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.
yep, I think it says that you just do:
checks = append(checks,
resource.TestCheckResourceAttr(resourceName, "num_partitions", "0"),
resource.TestCheckResourceAttr(datasourceName, "num_partitions", "0"),
)
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.
thank you! changed
| var ret int | ||
| checks = append(checks, | ||
| resource.TestCheckResourceAttr(resourceName, "num_partitions", strconv.Itoa(ret)), | ||
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", strconv.Itoa(ret)), | ||
| ) |
Copilot
AI
Dec 16, 2025
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 variable ret is declared but never assigned a value, making its purpose unclear. Since it will always be 0 (the zero value for int), it would be clearer to either use '0' directly in the string, use strconv.Itoa(0), or rename the variable to something like defaultNumPartitions with an explicit assignment to 0.
| resource.TestCheckResourceAttr(resourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | ||
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), |
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.
| resource.TestCheckResourceAttr(resourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | |
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | |
| resource.TestCheckResourceAttr(resourceName, "num_partitions", strconv.Itoa(*numPartitions)), | |
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", strconv.Itoa(*numPartitions)), |
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.
thank you! changed
| resource.TestCheckResourceAttr(resourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | ||
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), |
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.
| resource.TestCheckResourceAttr(resourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | |
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", fmt.Sprintf("%d", *numPartitions)), | |
| resource.TestCheckResourceAttr(resourceName, "num_partitions", strconv.Itoa(*numPartitions)), | |
| resource.TestCheckResourceAttr(datasourceName, "num_partitions", strconv.Itoa(*numPartitions)), |
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.
thank you! changed
|
note that a PR check is failing: |
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.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type = "search" | ||
| %[6]s | ||
| depends_on = [mongodbatlas_search_deployment.test] |
Copilot
AI
Dec 17, 2025
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.
Inconsistent indentation in the depends_on line. The line uses a tab character while other lines in the same configuration use spaces. Consider using consistent indentation throughout the configuration string.
| depends_on = [mongodbatlas_search_deployment.test] | |
| depends_on = [mongodbatlas_search_deployment.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 |
Copilot
AI
Dec 17, 2025
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.
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.
if default value is 1(it says so in the API docs), why we return 0? seems like an inconsistency in the API?
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.
@oarbusi 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.
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.
WDYT?
| * `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 |
Copilot
AI
Dec 17, 2025
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.
Description
The numPartitions field for MongoDB Atlas Search Index exists in the API, but Terraform can't manage it yet. The API overwrites nested fields like definition.numPartitions entirely (similar to PUT), making partial updates via PATCH unsupported. For now, customers need to use the MongoDB Atlas UI to manage this field until Terraform adds support.
This PR is for the addition of the
num_partitionsfield inmongodbatlas_search_indexLink to any related issue(s): CLOUDP-365383
Type of change:
Required Checklist:
Further comments