Skip to content

Commit

Permalink
INTMDB-251: Update search rs and ds to use go-client v0.12.0 (#548)
Browse files Browse the repository at this point in the history
* update search rs and ds to use go-client v0.12.0

* fix lint issue

* fixes

* added upgrade guide to search index
  • Loading branch information
abner-dou committed Aug 31, 2021
1 parent 4943267 commit 8a48c35
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 602 deletions.
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.4.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=
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
2 changes: 1 addition & 1 deletion mongodbatlas/data_source_mongodbatlas_search_index_test.go
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

0 comments on commit 8a48c35

Please sign in to comment.