@@ -95,6 +95,7 @@ func resourceTencentCloudClsIndex() *schema.Resource {
95
95
Type : schema .TypeList ,
96
96
MaxItems : 1 ,
97
97
Optional : true ,
98
+ Computed : true ,
98
99
Description : "Index rule." ,
99
100
Elem : & schema.Resource {
100
101
Schema : map [string ]* schema.Schema {
@@ -438,38 +439,54 @@ func resourceTencentCloudClsIndexRead(d *schema.ResourceData, meta interface{})
438
439
ruleMap := map [string ]interface {}{}
439
440
440
441
if res .Rule .FullText != nil {
441
- fullTextMap := map [string ]interface {}{
442
- "case_sensitive" : res .Rule .FullText .CaseSensitive ,
443
- "tokenizer" : res .Rule .FullText .Tokenizer ,
444
- "contain_z_h" : res .Rule .FullText .ContainZH ,
442
+ FullTextMap := map [string ]interface {}{}
443
+ if res .Rule .FullText .CaseSensitive != nil {
444
+ FullTextMap ["case_sensitive" ] = res .Rule .FullText .CaseSensitive
445
+ }
446
+ if res .Rule .FullText .Tokenizer != nil {
447
+ FullTextMap ["tokenizer" ] = res .Rule .FullText .Tokenizer
448
+ }
449
+ if res .Rule .FullText .ContainZH != nil {
450
+ FullTextMap ["contain_z_h" ] = res .Rule .FullText .ContainZH
445
451
}
446
- ruleMap ["full_text" ] = []interface {}{fullTextMap }
452
+
453
+ ruleMap ["full_text" ] = []interface {}{FullTextMap }
447
454
}
448
455
449
456
if res .Rule .KeyValue != nil {
450
- ruleKeyValueMap := map [string ]interface {}{
451
- "case_sensitive" : res .Rule .KeyValue .CaseSensitive ,
457
+ RuleKeyValueMap := map [string ]interface {}{}
458
+ if res .Rule .KeyValue .CaseSensitive != nil {
459
+ RuleKeyValueMap ["case_sensitive" ] = res .Rule .KeyValue .CaseSensitive
452
460
}
461
+
453
462
if res .Rule .KeyValue .KeyValues != nil {
454
463
keyValuesList := []interface {}{}
455
464
for _ , keyValueInfo := range res .Rule .KeyValue .KeyValues {
456
- keyValueInfoMap := map [string ]interface {}{
457
- "key" : keyValueInfo .Key ,
465
+ keyValueInfoMap := map [string ]interface {}{}
466
+ if keyValueInfo .Key != nil {
467
+ keyValueInfoMap ["key" ] = keyValueInfo .Key
458
468
}
459
469
if keyValueInfo .Value != nil {
460
- valueInfoMap := map [string ]interface {}{
461
- "type" : keyValueInfo .Value .Type ,
462
- "tokenizer" : keyValueInfo .Value .Tokenizer ,
463
- "sql_flag" : keyValueInfo .Value .SqlFlag ,
464
- "contain_z_h" : keyValueInfo .Value .ContainZH ,
470
+ valueInfoMap := map [string ]interface {}{}
471
+ if keyValueInfo .Value .Type != nil {
472
+ valueInfoMap ["type" ] = keyValueInfo .Value .Type
473
+ }
474
+ if keyValueInfo .Value .Tokenizer != nil {
475
+ valueInfoMap ["tokenizer" ] = keyValueInfo .Value .Tokenizer
476
+ }
477
+ if keyValueInfo .Value .SqlFlag != nil {
478
+ valueInfoMap ["sql_flag" ] = keyValueInfo .Value .SqlFlag
479
+ }
480
+ if keyValueInfo .Value .ContainZH != nil {
481
+ valueInfoMap ["contain_z_h" ] = keyValueInfo .Value .ContainZH
465
482
}
466
483
keyValueInfoMap ["value" ] = []interface {}{valueInfoMap }
467
484
}
468
485
keyValuesList = append (keyValuesList , keyValueInfoMap )
469
486
}
470
- ruleKeyValueMap ["key_values" ] = keyValuesList
487
+ RuleKeyValueMap ["key_values" ] = keyValuesList
471
488
}
472
- ruleMap ["key_value" ] = []interface {}{ruleKeyValueMap }
489
+ ruleMap ["key_value" ] = []interface {}{RuleKeyValueMap }
473
490
}
474
491
475
492
if res .Rule .Tag != nil {
@@ -529,7 +546,7 @@ func resourceTencentCloudClsIndexUpdate(d *schema.ResourceData, meta interface{}
529
546
530
547
request .TopicId = & id
531
548
532
- if d .HasChange ("rule" ) || d . HasChange ( "status" ) || d . HasChange ( "include_internal_fields" ) || d . HasChange ( "metadata_flag" ) {
549
+ if d .HasChange ("rule" ) {
533
550
if dMap , ok := helper .InterfacesHeadMap (d , "rule" ); ok {
534
551
ruleInfo := cls.RuleInfo {}
535
552
if fullTextMap , ok := helper .InterfaceToMap (dMap , "full_text" ); ok {
@@ -618,34 +635,38 @@ func resourceTencentCloudClsIndexUpdate(d *schema.ResourceData, meta interface{}
618
635
}
619
636
request .Rule = & ruleInfo
620
637
}
638
+ }
621
639
640
+ if d .HasChange ("status" ) {
622
641
if v , ok := d .GetOk ("status" ); ok {
623
642
request .Status = helper .Bool (v .(bool ))
624
643
}
625
-
644
+ }
645
+ if d .HasChange ("include_internal_fields" ) {
626
646
if v , ok := d .GetOk ("include_internal_fields" ); ok {
627
647
request .IncludeInternalFields = helper .Bool (v .(bool ))
628
648
}
629
-
649
+ }
650
+ if d .HasChange ("metadata_flag" ) {
630
651
if v , ok := d .GetOk ("metadata_flag" ); ok {
631
652
request .MetadataFlag = helper .IntUint64 (v .(int ))
632
653
}
633
-
634
- err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
635
- result , e := meta .(* TencentCloudClient ).apiV3Conn .UseClsClient ().ModifyIndex (request )
636
- if e != nil {
637
- return retryError (e )
638
- } else {
639
- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
640
- logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
641
- }
642
- return nil
643
- })
644
-
645
- if err != nil {
646
- return err
654
+ }
655
+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
656
+ result , e := meta .(* TencentCloudClient ).apiV3Conn .UseClsClient ().ModifyIndex (request )
657
+ if e != nil {
658
+ return retryError (e )
659
+ } else {
660
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " ,
661
+ logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
647
662
}
663
+ return nil
664
+ })
665
+
666
+ if err != nil {
667
+ return err
648
668
}
669
+
649
670
return resourceTencentCloudClsIndexRead (d , meta )
650
671
}
651
672
0 commit comments