@@ -54,6 +54,7 @@ import (
54
54
"context"
55
55
"errors"
56
56
"fmt"
57
+ sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
57
58
"log"
58
59
59
60
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
@@ -416,13 +417,21 @@ func resourceTencentCloudElasticsearchInstanceCreate(d *schema.ResourceData, met
416
417
}
417
418
d .SetId (instanceId )
418
419
420
+ instanceEmptyRetries := 5
419
421
err = resource .Retry (15 * readRetryTimeout , func () * resource.RetryError {
420
422
instance , errRet := elasticsearchService .DescribeInstanceById (ctx , instanceId )
421
423
if errRet != nil {
422
424
return retryError (errRet , InternalError )
423
425
}
424
- if instance == nil || * instance .Status == ES_INSTANCE_STATUS_PROCESSING {
425
- return resource .RetryableError (fmt .Errorf ("elasticsearch instance status is processing, retry... status:%v" , * instance .Status ))
426
+ if instance == nil {
427
+ if instanceEmptyRetries > 0 {
428
+ instanceEmptyRetries -= 1
429
+ return resource .RetryableError (fmt .Errorf ("cannot find instance %s, retrying" , instanceId ))
430
+ }
431
+ return resource .NonRetryableError (fmt .Errorf ("instance %s not exists" , instanceId ))
432
+ }
433
+ if * instance .Status != ES_INSTANCE_STATUS_NORMAL {
434
+ return resource .RetryableError (fmt .Errorf ("elasticsearch instance status is %v, retrying" , * instance .Status ))
426
435
}
427
436
return nil
428
437
})
@@ -515,6 +524,13 @@ func resourceTencentCloudElasticsearchInstanceRead(d *schema.ResourceData, meta
515
524
}
516
525
_ = d .Set ("node_info_list" , nodeInfoList )
517
526
527
+ if webInfo := instance .WebNodeTypeInfo ; webInfo != nil {
528
+ _ = helper .SetMapInterfaces (d , "web_node_type_info" , map [string ]interface {}{
529
+ "node_type" : webInfo .NodeType ,
530
+ "node_num" : webInfo .NodeNum ,
531
+ })
532
+ }
533
+
518
534
if instance .EsAcl != nil {
519
535
esAcls := make ([]map [string ]interface {}, 0 , 1 )
520
536
esAcl := map [string ]interface {}{
@@ -575,7 +591,6 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
575
591
if err != nil {
576
592
return err
577
593
}
578
- d .SetPartial ("password" )
579
594
}
580
595
581
596
if d .HasChange ("version" ) {
@@ -590,26 +605,16 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
590
605
if err != nil {
591
606
return err
592
607
}
593
- d .SetPartial ("version" )
594
608
595
- err = resource .Retry (10 * readRetryTimeout , func () * resource.RetryError {
596
- instance , errRet := elasticsearchService .DescribeInstanceById (ctx , instanceId )
597
- if errRet != nil {
598
- return retryError (errRet , InternalError )
599
- }
600
- if instance != nil && * instance .Status == ES_INSTANCE_STATUS_PROCESSING {
601
- return resource .RetryableError (errors .New ("elasticsearch instance status is processing, retry..." ))
602
- }
603
- return nil
604
- })
609
+ err = tencentCloudElasticsearchInstanceUpgradeWaiting (ctx , & elasticsearchService , instanceId )
605
610
if err != nil {
606
611
return err
607
612
}
608
613
}
609
614
610
615
if d .HasChange ("license_type" ) {
611
616
licenseType := d .Get ("license_type" ).(string )
612
- err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
617
+ err := resource .Retry (writeRetryTimeout * 2 , func () * resource.RetryError {
613
618
errRet := elasticsearchService .UpdateInstanceLicense (ctx , instanceId , licenseType )
614
619
if errRet != nil {
615
620
return retryError (errRet )
@@ -619,36 +624,37 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
619
624
if err != nil {
620
625
return err
621
626
}
622
- d .SetPartial ("license_type" )
623
627
624
- err = resource .Retry (10 * readRetryTimeout , func () * resource.RetryError {
625
- instance , errRet := elasticsearchService .DescribeInstanceById (ctx , instanceId )
626
- if errRet != nil {
627
- return retryError (errRet , InternalError )
628
- }
629
- if instance != nil && * instance .Status == ES_INSTANCE_STATUS_PROCESSING {
630
- return resource .RetryableError (errors .New ("elasticsearch instance status is processing, retry..." ))
631
- }
632
- return nil
633
- })
628
+ err = tencentCloudElasticsearchInstanceUpgradeWaiting (ctx , & elasticsearchService , instanceId )
634
629
if err != nil {
635
630
return err
636
631
}
637
632
}
638
633
639
634
if d .HasChange ("basic_security_type" ) {
640
635
basicSecurityType := d .Get ("basic_security_type" ).(int )
641
- err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
636
+ licenseType := d .Get ("license_type" ).(string )
637
+ licenseTypeUpgrading := licenseType != "oss"
638
+ err := resource .Retry (writeRetryTimeout * 2 , func () * resource.RetryError {
642
639
errRet := elasticsearchService .UpdateInstance (ctx , instanceId , "" , "" , int64 (basicSecurityType ), nil , nil , nil )
643
640
if errRet != nil {
641
+ err := errRet .(* sdkErrors.TencentCloudSDKError )
642
+ if err .Code == es .INVALIDPARAMETER && licenseTypeUpgrading {
643
+ return resource .RetryableError (fmt .Errorf ("waiting for licenseType update" ))
644
+ }
644
645
return retryError (errRet )
645
646
}
647
+
646
648
return nil
647
649
})
648
650
if err != nil {
649
651
return err
650
652
}
651
- d .SetPartial ("basic_security_type" )
653
+ err = tencentCloudElasticsearchInstanceUpgradeWaiting (ctx , & elasticsearchService , instanceId )
654
+
655
+ if err != nil {
656
+ return err
657
+ }
652
658
}
653
659
654
660
if d .HasChange ("web_node_type_info" ) {
@@ -660,7 +666,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
660
666
NodeNum : helper .IntUint64 (value ["node_num" ].(int )),
661
667
NodeType : helper .String (value ["node_type" ].(string )),
662
668
}
663
- err = resource .Retry (writeRetryTimeout , func () * resource.RetryError {
669
+ err = resource .Retry (writeRetryTimeout * 2 , func () * resource.RetryError {
664
670
errRet := elasticsearchService .UpdateInstance (ctx , instanceId , "" , "" , 0 , nil , info , nil )
665
671
if errRet != nil {
666
672
return retryError (errRet )
@@ -672,6 +678,10 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
672
678
if err != nil {
673
679
return err
674
680
}
681
+ err = tencentCloudElasticsearchInstanceUpgradeWaiting (ctx , & elasticsearchService , instanceId )
682
+ if err != nil {
683
+ return err
684
+ }
675
685
}
676
686
677
687
if d .HasChange ("node_info_list" ) {
@@ -695,7 +705,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
695
705
}
696
706
nodeInfoList = append (nodeInfoList , & dataDisk )
697
707
}
698
- err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
708
+ err := resource .Retry (writeRetryTimeout * 2 , func () * resource.RetryError {
699
709
errRet := elasticsearchService .UpdateInstance (ctx , instanceId , "" , "" , 0 , nodeInfoList , nil , nil )
700
710
if errRet != nil {
701
711
return retryError (errRet )
@@ -705,17 +715,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
705
715
if err != nil {
706
716
return err
707
717
}
708
- d .SetPartial ("node_info_list" )
709
- err = resource .Retry (10 * readRetryTimeout , func () * resource.RetryError {
710
- instance , errRet := elasticsearchService .DescribeInstanceById (ctx , instanceId )
711
- if errRet != nil {
712
- return retryError (errRet , InternalError )
713
- }
714
- if instance != nil && * instance .Status == ES_INSTANCE_STATUS_PROCESSING {
715
- return resource .RetryableError (errors .New ("elasticsearch instance status is processing, retry..." ))
716
- }
717
- return nil
718
- })
718
+ err = tencentCloudElasticsearchInstanceUpgradeWaiting (ctx , & elasticsearchService , instanceId )
719
719
if err != nil {
720
720
return err
721
721
}
@@ -732,7 +732,6 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
732
732
if err != nil {
733
733
return err
734
734
}
735
- d .SetPartial ("tags" )
736
735
}
737
736
if d .HasChange ("es_acl" ) {
738
737
esAcl := es.EsAcl {}
@@ -751,7 +750,7 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
751
750
}
752
751
}
753
752
754
- err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
753
+ err := resource .Retry (writeRetryTimeout * 2 , func () * resource.RetryError {
755
754
errRet := elasticsearchService .UpdateInstance (ctx , instanceId , "" , "" , 0 , nil , nil , & esAcl )
756
755
if errRet != nil {
757
756
return retryError (errRet )
@@ -761,12 +760,11 @@ func resourceTencentCloudElasticsearchInstanceUpdate(d *schema.ResourceData, met
761
760
if err != nil {
762
761
return err
763
762
}
764
- d .SetPartial ("es_acl" )
765
763
}
766
764
767
765
d .Partial (false )
768
766
769
- return nil
767
+ return resourceTencentCloudElasticsearchInstanceRead ( d , meta )
770
768
}
771
769
772
770
func resourceTencentCloudElasticsearchInstanceDelete (d * schema.ResourceData , meta interface {}) error {
@@ -805,3 +803,25 @@ func resourceTencentCloudElasticsearchInstanceDelete(d *schema.ResourceData, met
805
803
806
804
return nil
807
805
}
806
+
807
+ func tencentCloudElasticsearchInstanceUpgradeWaiting (ctx context.Context , service * ElasticsearchService , instanceId string ) error {
808
+ statusChangeRetries := 5
809
+ return resource .Retry (10 * readRetryTimeout , func () * resource.RetryError {
810
+ instance , errRet := service .DescribeInstanceById (ctx , instanceId )
811
+ if errRet != nil {
812
+ return retryError (errRet , InternalError )
813
+ }
814
+ if instance == nil {
815
+ return resource .NonRetryableError (fmt .Errorf ("instance %s not exist" , instanceId ))
816
+ }
817
+ if * instance .Status == ES_INSTANCE_STATUS_NORMAL && statusChangeRetries > 0 {
818
+ statusChangeRetries -= 1
819
+ err := fmt .Errorf ("instance %s waiting for upgrade status change, %d times remaining" , instanceId , statusChangeRetries )
820
+ return resource .RetryableError (err )
821
+ }
822
+ if * instance .Status == ES_INSTANCE_STATUS_PROCESSING {
823
+ return resource .RetryableError (errors .New ("elasticsearch instance status is processing, retry..." ))
824
+ }
825
+ return nil
826
+ })
827
+ }
0 commit comments