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

refactor: Migrates search index resource and data sources to new SDK #1536

Merged
merged 12 commits into from
Oct 19, 2023

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Oct 18, 2023

Description

Jira ticket: INTMDB-1195

Migrates search index resource and data sources to new SDK.

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@lantoli lantoli requested a review from a team as a code owner October 18, 2023 17:01
@lantoli lantoli marked this pull request as draft October 18, 2023 17:02
@lantoli lantoli changed the title Read refactor: Migrates search index resource to new SDK Oct 18, 2023
@lantoli lantoli changed the title refactor: Migrates search index resource to new SDK refactor: Migrates search index resource and data sources to new SDK Oct 19, 2023
options := &matlas.ListOptions{
PageNum: d.Get("page_num").(int),
ItemsPerPage: d.Get("items_per_page").(int),
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still pending what to do with page_num and items_per_page, but please review the rest of the PR

Copy link
Member Author

@lantoli lantoli Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be done in another PR to better track changelog

@lantoli lantoli marked this pull request as ready for review October 19, 2023 08:41
mongodbatlas/resource_mongodbatlas_search_index.go Outdated Show resolved Hide resolved

mappingFieldJSON, err := json.Marshal(fields)
return string(mappingFieldJSON), err
func marshalSearchIndex(fields any) (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we changing from []map[string]interface{} to any?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe better []map[string]any?

Copy link
Member Author

@lantoli lantoli Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is just realling calling json.Marshal that accepts any.
so i joined marshallSearchIndexAnalyzers and marshallSearchIndexMappingsField that accepts an array or a map into the same fuction, no need to have separate functions for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could rename the function directly to something more representative, like toJsonString

Copy link
Member Author

@lantoli lantoli Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of calling Marshal as there is an opossed method to unmarshal, and SearchIndex as it's meant to be used in this resource. so marshal as packaging the info (that turns out to be in json) and unmarshaling to unpackage it

@@ -258,10 +258,10 @@ An [Atlas Search analyzer](https://docs.atlas.mongodb.com/reference/atlas-search

* `token_filters` - Array containing zero or more token filters. Always require a type field, and some take additional options as well:
```terraform
"tokenFilters":{
"tokenFilters":[{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR is gonna be a breaking change?

Copy link
Member Author

@lantoli lantoli Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we agreed with @Zuhairahmed that this is not a breaking change but a documentation bug. In fact the title is fine "Array containing zero or more token filters" but the example is wrong

@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 2%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator 68%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util 12%
Summary 3% (271 / 10294)

Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lantoli lantoli merged commit 7a05d81 into master Oct 19, 2023
19 checks passed
@lantoli lantoli deleted the INTMDB-1195_resource_search_index branch October 19, 2023 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants