@@ -564,7 +564,11 @@ func mysqlCreateInstancePayByUse(ctx context.Context, d *schema.ResourceData, me
564
564
if len (response .Response .InstanceIds ) != 1 {
565
565
return fmt .Errorf ("mysql CreateDBInstanceHour return len(InstanceIds) is not 1,but %d" , len (response .Response .InstanceIds ))
566
566
}
567
- d .SetId (* response .Response .InstanceIds [0 ])
567
+
568
+ id := * response .Response .InstanceIds [0 ]
569
+
570
+ d .SetId (id )
571
+
568
572
return nil
569
573
}
570
574
@@ -618,6 +622,52 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
618
622
return err
619
623
}
620
624
625
+ // Initialize mysql instance
626
+ var (
627
+ password = d .Get ("root_password" ).(string )
628
+ charset = d .Get ("parameters.character_set_server" ).(string )
629
+ lowercase = d .Get ("parameters.lower_case_table_names" ).(string )
630
+ vPort int
631
+ )
632
+
633
+ port , portOk := d .GetOk ("intranet_port" )
634
+
635
+ if portOk && port .(int ) != 0 {
636
+ vPort = port .(int )
637
+ }
638
+
639
+ aReqId , err := mysqlService .InitDBInstances (ctx , mysqlID , password , charset , lowercase , vPort )
640
+
641
+ if err != nil {
642
+ return err
643
+ }
644
+
645
+ err = resource .Retry (readRetryTimeout , func () * resource.RetryError {
646
+ // Available status:INITIAL, RUNNING, SUCCESS, FAILED, KILLED, REMOVED, PAUSED
647
+ taskStatus , message , err := mysqlService .DescribeAsyncRequestInfo (ctx , aReqId )
648
+
649
+ if err != nil {
650
+ if _ , ok := err .(* errors.TencentCloudSDKError ); ! ok {
651
+ return resource .RetryableError (err )
652
+ } else {
653
+ return resource .NonRetryableError (err )
654
+ }
655
+ }
656
+ if taskStatus == MYSQL_TASK_STATUS_SUCCESS {
657
+ return nil
658
+ }
659
+ if taskStatus == MYSQL_TASK_STATUS_INITIAL || taskStatus == MYSQL_TASK_STATUS_RUNNING {
660
+ return resource .RetryableError (fmt .Errorf ("create account task status is %s" , taskStatus ))
661
+ }
662
+ err = fmt .Errorf ("initialize db task status is %s,we won't wait for it finish ,it show message:%s" , "," ,
663
+ message )
664
+ return resource .NonRetryableError (err )
665
+ })
666
+
667
+ if err != nil {
668
+ log .Printf ("[WARN] initial DB error: %s" , err .Error ())
669
+ }
670
+
621
671
//internet service
622
672
internetService := d .Get ("internet_service" ).(int )
623
673
if internetService == 1 {
0 commit comments