@@ -95,6 +95,7 @@ func resourceTencentCloudClsIndex() *schema.Resource {
9595 Type : schema .TypeList ,
9696 MaxItems : 1 ,
9797 Optional : true ,
98+ Computed : true ,
9899 Description : "Index rule." ,
99100 Elem : & schema.Resource {
100101 Schema : map [string ]* schema.Schema {
@@ -438,38 +439,54 @@ func resourceTencentCloudClsIndexRead(d *schema.ResourceData, meta interface{})
438439 ruleMap := map [string ]interface {}{}
439440
440441 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
445451 }
446- ruleMap ["full_text" ] = []interface {}{fullTextMap }
452+
453+ ruleMap ["full_text" ] = []interface {}{FullTextMap }
447454 }
448455
449456 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
452460 }
461+
453462 if res .Rule .KeyValue .KeyValues != nil {
454463 keyValuesList := []interface {}{}
455464 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
458468 }
459469 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
465482 }
466483 keyValueInfoMap ["value" ] = []interface {}{valueInfoMap }
467484 }
468485 keyValuesList = append (keyValuesList , keyValueInfoMap )
469486 }
470- ruleKeyValueMap ["key_values" ] = keyValuesList
487+ RuleKeyValueMap ["key_values" ] = keyValuesList
471488 }
472- ruleMap ["key_value" ] = []interface {}{ruleKeyValueMap }
489+ ruleMap ["key_value" ] = []interface {}{RuleKeyValueMap }
473490 }
474491
475492 if res .Rule .Tag != nil {
@@ -529,7 +546,7 @@ func resourceTencentCloudClsIndexUpdate(d *schema.ResourceData, meta interface{}
529546
530547 request .TopicId = & id
531548
532- if d .HasChange ("rule" ) || d . HasChange ( "status" ) || d . HasChange ( "include_internal_fields" ) || d . HasChange ( "metadata_flag" ) {
549+ if d .HasChange ("rule" ) {
533550 if dMap , ok := helper .InterfacesHeadMap (d , "rule" ); ok {
534551 ruleInfo := cls.RuleInfo {}
535552 if fullTextMap , ok := helper .InterfaceToMap (dMap , "full_text" ); ok {
@@ -618,34 +635,38 @@ func resourceTencentCloudClsIndexUpdate(d *schema.ResourceData, meta interface{}
618635 }
619636 request .Rule = & ruleInfo
620637 }
638+ }
621639
640+ if d .HasChange ("status" ) {
622641 if v , ok := d .GetOk ("status" ); ok {
623642 request .Status = helper .Bool (v .(bool ))
624643 }
625-
644+ }
645+ if d .HasChange ("include_internal_fields" ) {
626646 if v , ok := d .GetOk ("include_internal_fields" ); ok {
627647 request .IncludeInternalFields = helper .Bool (v .(bool ))
628648 }
629-
649+ }
650+ if d .HasChange ("metadata_flag" ) {
630651 if v , ok := d .GetOk ("metadata_flag" ); ok {
631652 request .MetadataFlag = helper .IntUint64 (v .(int ))
632653 }
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 ())
647662 }
663+ return nil
664+ })
665+
666+ if err != nil {
667+ return err
648668 }
669+
649670 return resourceTencentCloudClsIndexRead (d , meta )
650671}
651672
0 commit comments