-
Notifications
You must be signed in to change notification settings - Fork 187
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
feat: Adds type and fields attributes in resource and data sources for search_index #1605
Conversation
caeba29
to
e457758
Compare
### Advanced (with custom analyzers) | ||
### Basic vector index | ||
```terraform | ||
resource "mongodbatlas_search_index" "test-basic-search-vector" { |
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.
@Zuhairahmed do we want a different example?
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.
@lantoli suggest for time being we leverage example that Atlas Search team has provided here for fields
parameter: https://www.mongodb.com/docs/atlas/atlas-search/field-types/knn-vector/#std-label-fts-data-types-knn-vector
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.
"fields": {
"plot_embedding": {
"type": "knnVector",
"dimensions": 1536,
"similarity": "euclidean"
}
}
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.
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.
thanks. your example won't work directly but adapting the idea. current "name" attribute is the index name, that doesn't change.
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.
SGTM
@@ -272,6 +293,10 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource | |||
return diag.Errorf("error setting `index_id` for search index (%s): %s", d.Id(), err) | |||
} | |||
|
|||
if err := d.Set("type", searchIndex.Type); err != nil { |
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 API always responds with a value for the type field? Would consider marking as computed or defining a default value in the schema to avoid inconsistencies in the state.
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 the index was created withouth type, it won't return type. API responds same as in creation so I won't use computed.
as it's defined as optional, it has default value = "" (zero value for strings), this is what we want. When refreshing the state the "type" attribute is added to the state with "" but no plan change is shown to the users.
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.
suggest to have this question/answer represented with a test, not necessarily blocking this PR (unless it's trivial creating it).
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!
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.
it would be good to add migration and acceptance tests to this change
@marcosuma I added an acceptance test and planning to add more. About migration (and unit) I think the idea is doing it in the new FW resources, this is not migrated yet. I did manual tests that showed a change in TF state (from unexisting Type and Fields to Type="", Fields=nil) but didn't trigger a plan change to the user. |
@@ -156,6 +175,45 @@ func TestAccSearchIndexRS_importBasic(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestAccSearchIndexRS_withVector(t *testing.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.
@marcosuma FYI basic acceptance test, planning to add more
…ime for them to be deleted
formatting
formatting
0e415bf
to
45fa280
Compare
|
@@ -272,6 +293,10 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource | |||
return diag.Errorf("error setting `index_id` for search index (%s): %s", d.Id(), err) | |||
} | |||
|
|||
if err := d.Set("type", searchIndex.Type); err != nil { |
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.
suggest to have this question/answer represented with a test, not necessarily blocking this PR (unless it's trivial creating it).
}) | ||
} | ||
|
||
func TestAccSearchIndexRS_withSearchType(t *testing.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.
@marcosuma FYI this tests checks that you can explicitly pass "search" as index type.
resource.TestCheckResourceAttr(datasourceName, "mappings_dynamic", "true"), | ||
resource.TestCheckResourceAttr(datasourceName, "search_analyzer", searchAnalyzer), | ||
resource.TestCheckResourceAttr(datasourceName, "name", indexName), | ||
resource.TestCheckResourceAttr(datasourceName, "type", ""), |
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.
@marcosuma FYI this tests checks that type is empty when created in that way
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 detail
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"fields": { |
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.
have we considered adding a conflictsWith validation to ensure vectorSearch attributes are not defined together with regular search attributes?
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.
at the end I preferred that all those checks are done in the server. If we do them in client-side there is some risk that both logics differ now or in the future.
Description
Jira ticket: INTMDB-1260
Adds type and fields attributes in resource and data sources for search_index.
Type of change:
Required Checklist:
Further comments