Skip to content

Commit 1acd734

Browse files
authored
INTMDB-341: Fix search_index update (#964)
* Fixed casing on search_index attribute casing in update. Updated formatting on test json * More formatting of string based tf configs
1 parent d5c8cca commit 1acd734

File tree

2 files changed

+110
-108
lines changed

2 files changed

+110
-108
lines changed

mongodbatlas/resource_mongodbatlas_search_index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour
180180
}
181181

182182
if d.HasChange("collection_name") {
183-
searchIndex.CollectionName = d.Get("collectionName").(string)
183+
searchIndex.CollectionName = d.Get("collection_name").(string)
184184
}
185185

186186
if d.HasChange("database") {
@@ -192,7 +192,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour
192192
}
193193

194194
if d.HasChange("search_analyzer") {
195-
searchIndex.SearchAnalyzer = d.Get("searchAnalyzer").(string)
195+
searchIndex.SearchAnalyzer = d.Get("search_analyzer").(string)
196196
}
197197

198198
if d.HasChange("mappings_dynamic") {

mongodbatlas/resource_mongodbatlas_search_index_test.go

Lines changed: 108 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -162,39 +162,35 @@ func testAccMongoDBAtlasSearchIndexConfig(projectID, clusterName string) string
162162
project_id = "%[1]s"
163163
name = "%[2]s"
164164
disk_size_gb = 10
165-
165+
166166
cluster_type = "REPLICASET"
167167
replication_specs {
168-
num_shards = 1
169-
regions_config {
170-
region_name = "US_EAST_2"
171-
electable_nodes = 3
172-
priority = 7
173-
read_only_nodes = 0
174-
}
168+
num_shards = 1
169+
regions_config {
170+
region_name = "US_EAST_2"
171+
electable_nodes = 3
172+
priority = 7
173+
read_only_nodes = 0
174+
}
175175
}
176-
177176
backup_enabled = false
178177
auto_scaling_disk_gb_enabled = false
179-
178+
180179
// Provider Settings "block"
181180
provider_name = "AWS"
182181
provider_instance_size_name = "M10"
183-
184182
}
185183
186184
resource "mongodbatlas_search_index" "test" {
187-
project_id = mongodbatlas_cluster.aws_conf.project_id
188-
cluster_name = mongodbatlas_cluster.aws_conf.name
189-
analyzer = "lucene.simple"
190-
collection_name = "collection_test"
191-
database = "database_test"
185+
project_id = mongodbatlas_cluster.aws_conf.project_id
186+
cluster_name = mongodbatlas_cluster.aws_conf.name
187+
analyzer = "lucene.simple"
188+
collection_name = "collection_test"
189+
database = "database_test"
192190
mappings_dynamic = "true"
193-
name = "name_test"
194-
search_analyzer = "lucene.standard"
191+
name = "name_test"
192+
search_analyzer = "lucene.standard"
195193
}
196-
197-
198194
`, projectID, clusterName)
199195
}
200196

@@ -207,13 +203,13 @@ func testAccMongoDBAtlasSearchIndexConfigAdvanced(projectID, clusterName string)
207203
208204
cluster_type = "REPLICASET"
209205
replication_specs {
210-
num_shards = 1
211-
regions_config {
212-
region_name = "US_EAST_2"
213-
electable_nodes = 3
214-
priority = 7
215-
read_only_nodes = 0
216-
}
206+
num_shards = 1
207+
regions_config {
208+
region_name = "US_EAST_2"
209+
electable_nodes = 3
210+
priority = 7
211+
read_only_nodes = 0
212+
}
217213
}
218214
219215
backup_enabled = false
@@ -226,69 +222,77 @@ func testAccMongoDBAtlasSearchIndexConfigAdvanced(projectID, clusterName string)
226222
}
227223
228224
resource "mongodbatlas_search_index" "test" {
229-
project_id = mongodbatlas_cluster.aws_conf.project_id
230-
cluster_name = mongodbatlas_cluster.aws_conf.name
225+
project_id = mongodbatlas_cluster.aws_conf.project_id
226+
cluster_name = mongodbatlas_cluster.aws_conf.name
231227
232-
analyzer = "lucene.simple"
233-
collection_name = "collection_test"
234-
database = "database_test"
228+
analyzer = "lucene.simple"
229+
collection_name = "collection_test"
230+
database = "database_test"
235231
mappings_dynamic = false
236-
mappings_fields = <<-EOF
237-
{
238-
"address": {
239-
"type": "document",
240-
"fields": {
241-
"city": {
242-
"type": "string",
243-
"analyzer": "lucene.simple",
244-
"ignoreAbove": 255
245-
},
246-
"state": {
247-
"type": "string",
248-
"analyzer": "lucene.english"
249-
}
232+
mappings_fields = <<-EOF
233+
{
234+
"address":{
235+
"type":"document",
236+
"fields":{
237+
"city":{
238+
"type":"string",
239+
"analyzer":"lucene.simple",
240+
"ignoreAbove":255
241+
},
242+
"state":{
243+
"type":"string",
244+
"analyzer":"lucene.english"
245+
}
250246
}
251-
},
252-
"company": {
253-
"type": "string",
254-
"analyzer": "lucene.whitespace",
255-
"multi": {
256-
"mySecondaryAnalyzer": {
257-
"type": "string",
258-
"analyzer": "lucene.french"
259-
}
247+
},
248+
"company":{
249+
"type":"string",
250+
"analyzer":"lucene.whitespace",
251+
"multi":{
252+
"mySecondaryAnalyzer":{
253+
"type":"string",
254+
"analyzer":"lucene.french"
255+
}
260256
}
261-
},
262-
"employees": {
263-
"type": "string",
264-
"analyzer": "lucene.standard"
265-
}
257+
},
258+
"employees":{
259+
"type":"string",
260+
"analyzer":"lucene.standard"
266261
}
267-
EOF
268-
name = "name_test"
269-
search_analyzer = "lucene.standard"
270-
analyzers = <<-EOF
271-
[{
272-
"name": "index_analyzer_test_name",
273-
"charFilters": [{
274-
"type": "mapping",
275-
"mappings": {"\\" : "/"}
276-
}],
277-
"tokenizer": [{
278-
"type": "nGram",
279-
"minGram": 2,
280-
"maxGram": 5
281-
}],
282-
"tokenFilters": [{
283-
"type": "length",
284-
"min": 20,
285-
"max": 33
286-
}]
287-
}]
262+
}
263+
EOF
264+
name = "name_test"
265+
search_analyzer = "lucene.standard"
266+
analyzers = <<-EOF
267+
[
268+
{
269+
"name":"index_analyzer_test_name",
270+
"charFilters":[
271+
{
272+
"type":"mapping",
273+
"mappings":{
274+
"\\":"/"
275+
}
276+
}
277+
],
278+
"tokenizer":[
279+
{
280+
"type":"nGram",
281+
"minGram":2,
282+
"maxGram":5s
283+
}
284+
],
285+
"tokenFilters":[
286+
{
287+
"type":"length",
288+
"min":20,
289+
"max":33
290+
}
291+
]
292+
}
293+
]
288294
EOF
289295
}
290-
291-
292296
`, projectID, clusterName)
293297
}
294298

@@ -298,44 +302,42 @@ func testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName string)
298302
project_id = "%[1]s"
299303
name = "%[2]s"
300304
disk_size_gb = 10
301-
305+
302306
cluster_type = "REPLICASET"
303307
replication_specs {
304-
num_shards = 1
305-
regions_config {
306-
region_name = "US_EAST_2"
307-
electable_nodes = 3
308-
priority = 7
309-
read_only_nodes = 0
310-
}
308+
num_shards = 1
309+
regions_config {
310+
region_name = "US_EAST_2"
311+
electable_nodes = 3
312+
priority = 7
313+
read_only_nodes = 0
314+
}
311315
}
312-
316+
313317
backup_enabled = false
314318
auto_scaling_disk_gb_enabled = false
315-
319+
316320
// Provider Settings "block"
317321
provider_name = "AWS"
318322
provider_instance_size_name = "M10"
319-
323+
320324
}
321-
325+
322326
resource "mongodbatlas_search_index" "test" {
323-
project_id = mongodbatlas_cluster.test_cluster.project_id
324-
cluster_name = mongodbatlas_cluster.test_cluster.name
325-
analyzer = "lucene.standard"
326-
collection_name = "collection_test"
327-
database = "database_test"
327+
project_id = mongodbatlas_cluster.test_cluster.project_id
328+
cluster_name = mongodbatlas_cluster.test_cluster.name
329+
analyzer = "lucene.standard"
330+
collection_name = "collection_test"
331+
database = "database_test"
328332
mappings_dynamic = "true"
329-
name = "name_test"
330-
search_analyzer = "lucene.standard"
333+
name = "name_test"
334+
search_analyzer = "lucene.standard"
331335
synonyms {
332-
analyzer = "lucene.simple"
333-
name = "synonym_test"
336+
analyzer = "lucene.simple"
337+
name = "synonym_test"
334338
source_collection = "collection_test"
335339
}
336340
}
337-
338-
339341
`, projectID, clusterName)
340342
}
341343

0 commit comments

Comments
 (0)