Skip to content

INTMDB-251: Update search rs and ds to use go-client v0.12.0 #548

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

Merged
merged 4 commits into from
Aug 31, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.3.1
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.11.0
go.mongodb.org/atlas v0.12.0
go.mongodb.org/realm v0.0.1
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,9 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6yfWfDmlWd35khcWpUa4L0xI/k=
go.mongodb.org/atlas v0.11.0 h1:fVVh+lFlqpGaUw2GhtETnQehV4ftucXksx6CRVdE+hI=
go.mongodb.org/atlas v0.11.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/atlas v0.12.0 h1:/vnHX3rh8jdPrP8mRznuU/2VrGH+cCdz8/Esrzpvaus=
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
Comment on lines +979 to +980
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] please run go mod tidy to clean the old version from this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure!

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I think it's still there because of the realm client... we can look at that on a different PR

go.mongodb.org/realm v0.0.1 h1:qh47ZkEMvlukKiKqcDDox5Lmx1Tk3krxwC7W9LhVGcc=
go.mongodb.org/realm v0.0.1/go.mod h1:4LzdATHVci61HSpYuqmRPISks5WQdB92u/aJRHNz9/0=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
22 changes: 12 additions & 10 deletions mongodbatlas/data_source_mongodbatlas_search_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func returnSearchIndexDSSchema() map[string]*schema.Schema {
Optional: true,
},
"analyzers": {
Type: schema.TypeSet,
Optional: true,
Elem: customAnalyzersSchema(),
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: validateSearchAnalyzersDiff,
},
"collection_name": {
Type: schema.TypeString,
Expand Down Expand Up @@ -95,13 +95,15 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour
return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err)
}

searchIndexCustomAnalyzers, err := flattenSearchIndexCustomAnalyzers(searchIndex.Analyzers)
if err != nil {
return nil
}
if len(searchIndex.Analyzers) > 0 {
searchIndexMappingFields, err := marshallSearchIndexAnalyzers(searchIndex.Analyzers)
if err != nil {
return diag.FromErr(err)
}

if err := d.Set("analyzers", searchIndexCustomAnalyzers); err != nil {
return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err)
if err := d.Set("analyzers", searchIndexMappingFields); err != nil {
return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err)
}
}

if err := d.Set("collection_name", searchIndex.CollectionName); err != nil {
Expand All @@ -125,7 +127,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour
}

if searchIndex.Mappings.Fields != nil {
searchIndexMappingFields, err := marshallSearchIndexMappingFields(*searchIndex.Mappings.Fields)
searchIndexMappingFields, err := marshallSearchIndexMappingsField(*searchIndex.Mappings.Fields)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceMongoDBAtlasSearchIndexes_byID(t *testing.T) {
func TestAccDataSourceMongoDBAtlasSearchIndex_byID(t *testing.T) {
var (
clusterName = acctest.RandomWithPrefix("test-acc-global")
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
Expand Down
16 changes: 9 additions & 7 deletions mongodbatlas/data_source_mongodbatlas_search_indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,8 @@ func flattenSearchIndexes(searchIndexes []*matlas.SearchIndex) ([]map[string]int
searchIndexesMap = make([]map[string]interface{}, len(searchIndexes))

for i := range searchIndexes {
searchIndexCustomAnalyzers, err := flattenSearchIndexCustomAnalyzers(searchIndexes[i].Analyzers)
if err != nil {
return nil, err
}

searchIndexesMap[i] = map[string]interface{}{
"analyzer": searchIndexes[i].Analyzer,
"analyzers": searchIndexCustomAnalyzers,
"collection_name": searchIndexes[i].CollectionName,
"database": searchIndexes[i].Database,
"index_id": searchIndexes[i].IndexID,
Expand All @@ -120,12 +114,20 @@ func flattenSearchIndexes(searchIndexes []*matlas.SearchIndex) ([]map[string]int
}

if searchIndexes[i].Mappings.Fields != nil {
searchIndexMappingFields, err := marshallSearchIndexMappingFields(*searchIndexes[i].Mappings.Fields)
searchIndexMappingFields, err := marshallSearchIndexMappingsField(*searchIndexes[i].Mappings.Fields)
if err != nil {
return nil, err
}
searchIndexesMap[i]["mappings_fields"] = searchIndexMappingFields
}

if len(searchIndexes[i].Analyzers) > 0 {
searchIndexAnalyzers, err := marshallSearchIndexAnalyzers(searchIndexes[i].Analyzers)
if err != nil {
return nil, err
}
searchIndexesMap[i]["analyzers"] = searchIndexAnalyzers
}
}

return searchIndexesMap, nil
Expand Down
Loading