@@ -581,6 +581,20 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
581
581
}
582
582
}
583
583
584
+ var (
585
+ rpgFlag bool
586
+ )
587
+
588
+ if v , ok := d .GetOkExists ("force_replace_placement_group_id" ); ok {
589
+ rpgFlag = v .(bool )
590
+ }
591
+
592
+ if ! rpgFlag {
593
+ if v , ok := d .GetOk ("placement_group_id" ); ok {
594
+ request .DisasterRecoverGroupIds = []* string {helper .String (v .(string ))}
595
+ }
596
+ }
597
+
584
598
// network
585
599
request .InternetAccessible = & cvm.InternetAccessible {}
586
600
if v , ok := d .GetOk ("internet_charge_type" ); ok {
@@ -837,54 +851,53 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
837
851
}
838
852
839
853
// set placement group id
840
- if v , ok := d .GetOk ("placement_group_id" ); ok && v != "" {
841
- request := cvm .NewModifyInstancesDisasterRecoverGroupRequest ()
842
- if v , ok := d .GetOkExists ("force_replace_placement_group_id" ); ok {
843
- request .Force = helper .Bool (v .(bool ))
844
- }
854
+ if rpgFlag {
855
+ if v , ok := d .GetOk ("placement_group_id" ); ok && v != "" {
856
+ request := cvm .NewModifyInstancesDisasterRecoverGroupRequest ()
857
+ request .InstanceIds = helper .Strings ([]string {instanceId })
858
+ request .DisasterRecoverGroupId = helper .String (v .(string ))
859
+ request .Force = helper .Bool (rpgFlag )
860
+ err = resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
861
+ result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCvmClient ().ModifyInstancesDisasterRecoverGroup (request )
862
+ if e != nil {
863
+ return tccommon .RetryError (e )
864
+ } else {
865
+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
866
+ }
845
867
846
- request .InstanceIds = helper .Strings ([]string {instanceId })
847
- request .DisasterRecoverGroupId = helper .String (v .(string ))
848
- err = resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
849
- result , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UseCvmClient ().ModifyInstancesDisasterRecoverGroup (request )
850
- if e != nil {
851
- return tccommon .RetryError (e )
852
- } else {
853
- log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
868
+ return nil
869
+ })
870
+
871
+ if err != nil {
872
+ return err
854
873
}
855
874
856
- return nil
857
- })
875
+ // wait
876
+ err = resource .Retry (d .Timeout (schema .TimeoutCreate ), func () * resource.RetryError {
877
+ instance , errRet := cvmService .DescribeInstanceById (ctx , instanceId )
878
+ if errRet != nil {
879
+ return tccommon .RetryError (errRet , tccommon .InternalError )
880
+ }
858
881
859
- if err != nil {
860
- return err
861
- }
882
+ if instance != nil && * instance .InstanceState == CVM_STATUS_LAUNCH_FAILED {
883
+ //LatestOperationCodeMode
884
+ if instance .LatestOperationErrorMsg != nil {
885
+ return resource .NonRetryableError (fmt .Errorf ("cvm instance %s launch failed. Error msg: %s.\n " , * instance .InstanceId , * instance .LatestOperationErrorMsg ))
886
+ }
862
887
863
- // wait
864
- err = resource .Retry (d .Timeout (schema .TimeoutCreate ), func () * resource.RetryError {
865
- instance , errRet := cvmService .DescribeInstanceById (ctx , instanceId )
866
- if errRet != nil {
867
- return tccommon .RetryError (errRet , tccommon .InternalError )
868
- }
888
+ return resource .NonRetryableError (fmt .Errorf ("cvm instance %s launch failed, this resource will not be stored to tfstate and will auto removed\n ." , * instance .InstanceId ))
889
+ }
869
890
870
- if instance != nil && * instance .InstanceState == CVM_STATUS_LAUNCH_FAILED {
871
- //LatestOperationCodeMode
872
- if instance .LatestOperationErrorMsg != nil {
873
- return resource .NonRetryableError (fmt .Errorf ("cvm instance %s launch failed. Error msg: %s.\n " , * instance .InstanceId , * instance .LatestOperationErrorMsg ))
891
+ if instance != nil && * instance .InstanceState == CVM_STATUS_RUNNING {
892
+ return nil
874
893
}
875
894
876
- return resource .NonRetryableError (fmt .Errorf ("cvm instance %s launch failed, this resource will not be stored to tfstate and will auto removed \n . " , * instance .InstanceId ))
877
- }
895
+ return resource .RetryableError (fmt .Errorf ("cvm instance status is %s, retry... " , * instance .InstanceState ))
896
+ })
878
897
879
- if instance != nil && * instance . InstanceState == CVM_STATUS_RUNNING {
880
- return nil
898
+ if err != nil {
899
+ return err
881
900
}
882
-
883
- return resource .RetryableError (fmt .Errorf ("cvm instance status is %s, retry..." , * instance .InstanceState ))
884
- })
885
-
886
- if err != nil {
887
- return err
888
901
}
889
902
}
890
903
0 commit comments