Skip to content

Commit

Permalink
resource/alicloud_instance: Added retry strategy for error code
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWolong authored and ChenHanZhang committed Dec 18, 2024
1 parent 2193633 commit b6a6312
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions alicloud/resource_alicloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,13 +1314,29 @@ func resourceAliCloudInstanceRead(d *schema.ResourceData, meta interface{}) erro
request := ecs.CreateDescribeInstanceAutoRenewAttributeRequest()
request.RegionId = client.RegionId
request.InstanceId = d.Id()
raw, err := client.WithEcsClient(func(ecsClient *ecs.Client) (interface{}, error) {
return ecsClient.DescribeInstanceAutoRenewAttribute(request)

var raw interface{}
var err error
wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
raw, err = client.WithEcsClient(func(ecsClient *ecs.Client) (interface{}, error) {
return ecsClient.DescribeInstanceAutoRenewAttribute(request)
})
if err != nil {
if NeedRetry(err) {
wait()
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
addDebug(request.GetActionName(), raw, request.RpcRequest, request)

if err != nil {
return WrapErrorf(err, DefaultErrorMsg, d.Id(), request.GetActionName(), AlibabaCloudSdkGoERROR)
}
addDebug(request.GetActionName(), raw, request.RpcRequest, request)

response, _ := raw.(*ecs.DescribeInstanceAutoRenewAttributeResponse)
periodUnit := d.Get("period_unit").(string)
if periodUnit == "" {
Expand Down

0 comments on commit b6a6312

Please sign in to comment.