From 94f83c8bbea1b21baed6e59bd26f0150e9218353 Mon Sep 17 00:00:00 2001 From: shinny-taojiachun Date: Mon, 25 Dec 2023 18:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80run=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=9B=E8=A1=A5=E5=85=85=E9=81=97=E6=BC=8Ferror=E5=90=8E?= =?UTF-8?q?=E7=9A=84return=E5=B9=B6=E5=88=A4=E6=96=AD=E4=BF=9D=E7=95=99err?= =?UTF-8?q?Update=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alicloud/resource_alicloud_instance.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/alicloud/resource_alicloud_instance.go b/alicloud/resource_alicloud_instance.go index 58082cc98dfc..181fd6d81c0c 100644 --- a/alicloud/resource_alicloud_instance.go +++ b/alicloud/resource_alicloud_instance.go @@ -1312,8 +1312,7 @@ func resourceAliyunInstanceUpdate(d *schema.ResourceData, meta interface{}) (err statusUpdate = false } if imageUpdate || vpcUpdate || passwordUpdate || typeUpdate || statusUpdate { - run = true - return WrapError(updateInstanceAsStopped(d, meta, run, target.(string), ecsService, client)) + return WrapError(updateInstanceAsStopped(d, meta, target.(string), ecsService, client)) } if err := modifyInstanceNetworkSpec(d, meta); err != nil { @@ -2200,7 +2199,7 @@ func modifyInstanceNetworkSpec(d *schema.ResourceData, meta interface{}) error { return nil } -func updateInstanceAsStopped(d *schema.ResourceData, meta interface{}, run bool, target string, ecsService EcsService, client *connectivity.AliyunClient) (errUpdate error) { +func updateInstanceAsStopped(d *schema.ResourceData, meta interface{}, target string, ecsService EcsService, client *connectivity.AliyunClient) (errUpdate error) { instance, errDesc := ecsService.DescribeInstance(d.Id()) if errDesc != nil { return WrapError(errDesc) @@ -2228,7 +2227,10 @@ func updateInstanceAsStopped(d *schema.ResourceData, meta interface{}, run bool, }) if err != nil { - errUpdate = WrapErrorf(err, DefaultErrorMsg, d.Id(), startRequest.GetActionName(), AlibabaCloudSdkGoERROR) + if errUpdate != nil { + errUpdate = WrapErrorf(err, DefaultErrorMsg, d.Id(), startRequest.GetActionName(), AlibabaCloudSdkGoERROR) + } + return } // Start instance sometimes costs more than 8 minutes when os type is centos. stateConf := &resource.StateChangeConf{ @@ -2241,7 +2243,10 @@ func updateInstanceAsStopped(d *schema.ResourceData, meta interface{}, run bool, } if _, err = stateConf.WaitForState(); err != nil { - errUpdate = WrapErrorf(err, IdMsg, d.Id()) + if errUpdate != nil { + errUpdate = WrapErrorf(err, IdMsg, d.Id()) + } + return } } }() @@ -2275,15 +2280,15 @@ func updateInstanceAsStopped(d *schema.ResourceData, meta interface{}, run bool, return WrapErrorf(err, IdMsg, d.Id()) } } - if _, err := modifyInstanceImage(d, meta, run); err != nil { + if _, err := modifyInstanceImage(d, meta, true); err != nil { return WrapError(err) } - if _, err := modifyVpcAttribute(d, meta, run); err != nil { + if _, err := modifyVpcAttribute(d, meta, true); err != nil { return WrapError(err) } - if _, err := modifyInstanceType(d, meta, run); err != nil { + if _, err := modifyInstanceType(d, meta, true); err != nil { return WrapError(err) }