Skip to content

Commit

Permalink
Add retry for error code in 'Route' (#136)
Browse files Browse the repository at this point in the history
* Add retry for error code in 'Route'

- Add retry, error : "1017013", "Route Table is setting. Please try again in a moment."

* Fix timeout type
  • Loading branch information
yoogledev authored Dec 14, 2020
1 parent 720b70e commit d9cc5ac
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions ncloud/resource_ncloud_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,24 @@ func resourceNcloudRouteCreate(d *schema.ResourceData, meta interface{}) error {
RouteList: []*vpc.RouteParameter{routeParams},
}

logCommonRequest("AddRoute", reqParams)
resp, err := config.Client.vpc.V2Api.AddRoute(reqParams)
var resp *vpc.AddRouteResponse
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
var err error

logCommonRequest("AddRoute", reqParams)
resp, err = config.Client.vpc.V2Api.AddRoute(reqParams)

if err != nil {
errBody, _ := GetCommonErrorBody(err)
if errBody.ReturnCode == "1017013" {
logErrorResponse("retry add Route", err, reqParams)
time.Sleep(time.Second * 5)
return resource.RetryableError(err)
}
}
return resource.NonRetryableError(err)
})

if err != nil {
logErrorResponse("AddRoute", err, reqParams)
return err
Expand Down Expand Up @@ -190,8 +206,24 @@ func resourceNcloudRouteDelete(d *schema.ResourceData, meta interface{}) error {
RouteList: []*vpc.RouteParameter{routeParams},
}

logCommonRequest("RemoveRoute", reqParams)
resp, err := config.Client.vpc.V2Api.RemoveRoute(reqParams)
var resp *vpc.RemoveRouteResponse
err := resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
var err error

logCommonRequest("RemoveRoute", reqParams)
resp, err = config.Client.vpc.V2Api.RemoveRoute(reqParams)

if err != nil {
errBody, _ := GetCommonErrorBody(err)
if errBody.ReturnCode == "1017013" {
logErrorResponse("retry remove Route", err, reqParams)
time.Sleep(time.Second * 5)
return resource.RetryableError(err)
}
}
return resource.NonRetryableError(err)
})

if err != nil {
logErrorResponse("RemoveRoute", err, reqParams)
return err
Expand Down

0 comments on commit d9cc5ac

Please sign in to comment.