Skip to content

Commit 0b5b2fa

Browse files
fix(cvm): 更换镜像提前关机时允许机器已经处于关机状态
1 parent e17dd55 commit 0b5b2fa

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

tencentcloud/resource_tc_instance.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -827,21 +827,19 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
827827
err = resource.Retry(writeRetryTimeout, func() *resource.RetryError {
828828
ratelimit.Check("create")
829829
response, runErr := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().RunInstances(request)
830-
if runErr != nil {
830+
if isExpectError(runErr, CVM_RETRYABLE_ERROR) {
831+
return resource.RetryableError(fmt.Errorf("cvm create error: %s, retrying", runErr.Error()))
832+
} else if isExpectError(runErr, []string{
833+
"ResourceInsufficient.AvailabilityZoneSoldOut",
834+
"ResourceInsufficient.SpecifiedInstanceType",
835+
"ResourceUnavailable.InstanceType",
836+
"ResourcesSoldOut.SpecifiedInstanceType",
837+
}) {
838+
// 开机失败,继续尝试下一个实例类型
839+
return resource.NonRetryableError(cvmResourceInsufficientError)
840+
} else if runErr != nil {
831841
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
832842
logId, request.GetAction(), request.ToJsonString(), runErr.Error())
833-
e, ok := runErr.(*sdkErrors.TencentCloudSDKError)
834-
if ok && IsContains(CVM_RETRYABLE_ERROR, e.Code) {
835-
return resource.RetryableError(fmt.Errorf("cvm create error: %s, retrying", e.Error()))
836-
} else if ok && IsContains([]string{
837-
"ResourceInsufficient.AvailabilityZoneSoldOut",
838-
"ResourceInsufficient.SpecifiedInstanceType",
839-
"ResourceUnavailable.InstanceType",
840-
"ResourcesSoldOut.SpecifiedInstanceType",
841-
}, e.Code) {
842-
// 开机失败,继续尝试下一个实例类型
843-
return resource.NonRetryableError(cvmResourceInsufficientError)
844-
}
845843
// 未知错误,直接报错
846844
return resource.NonRetryableError(runErr)
847845
}
@@ -1376,7 +1374,8 @@ func resourceTencentCloudInstanceUpdate(d *schema.ResourceData, meta interface{}
13761374
d.HasChange("keep_image_login") {
13771375

13781376
err = cvmService.StopInstance(ctx, instanceId, "KEEP_CHARGING")
1379-
if err != nil {
1377+
// continue when instance has been stopped
1378+
if err != nil && !isExpectError(err, []string{"UnsupportedOperation.InstanceStateStopped"}) {
13801379
return
13811380
}
13821381
err = resource.Retry(2*readRetryTimeout, func() *resource.RetryError {

0 commit comments

Comments
 (0)