Skip to content

Commit 8a48c35

Browse files
authored
INTMDB-251: Update search rs and ds to use go-client v0.12.0 (#548)
* update search rs and ds to use go-client v0.12.0 * fix lint issue * fixes * added upgrade guide to search index
1 parent 4943267 commit 8a48c35

9 files changed

+245
-602
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ require (
1212
github.com/mwielbut/pointy v1.1.0
1313
github.com/spf13/cast v1.4.1
1414
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
15-
go.mongodb.org/atlas v0.11.0
15+
go.mongodb.org/atlas v0.12.0
1616
go.mongodb.org/realm v0.0.1
1717
)

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,9 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
975975
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
976976
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
977977
go.etcd.io/etcd v0.0.0-20200513171258-e048e166ab9c/go.mod h1:xCI7ZzBfRuGgBXyXO6yfWfDmlWd35khcWpUa4L0xI/k=
978-
go.mongodb.org/atlas v0.11.0 h1:fVVh+lFlqpGaUw2GhtETnQehV4ftucXksx6CRVdE+hI=
979978
go.mongodb.org/atlas v0.11.0/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
979+
go.mongodb.org/atlas v0.12.0 h1:/vnHX3rh8jdPrP8mRznuU/2VrGH+cCdz8/Esrzpvaus=
980+
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
980981
go.mongodb.org/realm v0.0.1 h1:qh47ZkEMvlukKiKqcDDox5Lmx1Tk3krxwC7W9LhVGcc=
981982
go.mongodb.org/realm v0.0.1/go.mod h1:4LzdATHVci61HSpYuqmRPISks5WQdB92u/aJRHNz9/0=
982983
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=

mongodbatlas/data_source_mongodbatlas_search_index.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func returnSearchIndexDSSchema() map[string]*schema.Schema {
3333
Optional: true,
3434
},
3535
"analyzers": {
36-
Type: schema.TypeSet,
37-
Optional: true,
38-
Elem: customAnalyzersSchema(),
36+
Type: schema.TypeString,
37+
Optional: true,
38+
DiffSuppressFunc: validateSearchAnalyzersDiff,
3939
},
4040
"collection_name": {
4141
Type: schema.TypeString,
@@ -95,13 +95,15 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour
9595
return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err)
9696
}
9797

98-
searchIndexCustomAnalyzers, err := flattenSearchIndexCustomAnalyzers(searchIndex.Analyzers)
99-
if err != nil {
100-
return nil
101-
}
98+
if len(searchIndex.Analyzers) > 0 {
99+
searchIndexMappingFields, err := marshallSearchIndexAnalyzers(searchIndex.Analyzers)
100+
if err != nil {
101+
return diag.FromErr(err)
102+
}
102103

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

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

127129
if searchIndex.Mappings.Fields != nil {
128-
searchIndexMappingFields, err := marshallSearchIndexMappingFields(*searchIndex.Mappings.Fields)
130+
searchIndexMappingFields, err := marshallSearchIndexMappingsField(*searchIndex.Mappings.Fields)
129131
if err != nil {
130132
return diag.FromErr(err)
131133
}

mongodbatlas/data_source_mongodbatlas_search_index_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
)
1111

12-
func TestAccDataSourceMongoDBAtlasSearchIndexes_byID(t *testing.T) {
12+
func TestAccDataSourceMongoDBAtlasSearchIndex_byID(t *testing.T) {
1313
var (
1414
clusterName = acctest.RandomWithPrefix("test-acc-global")
1515
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")

mongodbatlas/data_source_mongodbatlas_search_indexes.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,8 @@ func flattenSearchIndexes(searchIndexes []*matlas.SearchIndex) ([]map[string]int
102102
searchIndexesMap = make([]map[string]interface{}, len(searchIndexes))
103103

104104
for i := range searchIndexes {
105-
searchIndexCustomAnalyzers, err := flattenSearchIndexCustomAnalyzers(searchIndexes[i].Analyzers)
106-
if err != nil {
107-
return nil, err
108-
}
109-
110105
searchIndexesMap[i] = map[string]interface{}{
111106
"analyzer": searchIndexes[i].Analyzer,
112-
"analyzers": searchIndexCustomAnalyzers,
113107
"collection_name": searchIndexes[i].CollectionName,
114108
"database": searchIndexes[i].Database,
115109
"index_id": searchIndexes[i].IndexID,
@@ -120,12 +114,20 @@ func flattenSearchIndexes(searchIndexes []*matlas.SearchIndex) ([]map[string]int
120114
}
121115

122116
if searchIndexes[i].Mappings.Fields != nil {
123-
searchIndexMappingFields, err := marshallSearchIndexMappingFields(*searchIndexes[i].Mappings.Fields)
117+
searchIndexMappingFields, err := marshallSearchIndexMappingsField(*searchIndexes[i].Mappings.Fields)
124118
if err != nil {
125119
return nil, err
126120
}
127121
searchIndexesMap[i]["mappings_fields"] = searchIndexMappingFields
128122
}
123+
124+
if len(searchIndexes[i].Analyzers) > 0 {
125+
searchIndexAnalyzers, err := marshallSearchIndexAnalyzers(searchIndexes[i].Analyzers)
126+
if err != nil {
127+
return nil, err
128+
}
129+
searchIndexesMap[i]["analyzers"] = searchIndexAnalyzers
130+
}
129131
}
130132

131133
return searchIndexesMap, nil

0 commit comments

Comments
 (0)