Skip to content

Commit

Permalink
Check if error is retryable before returning that it is
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Sep 17, 2018
1 parent 3816b0a commit 3f2d188
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion azurerm/resource_arm_role_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package azurerm
import (
"fmt"
"log"
"net/url"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/Azure/go-autorest/autorest"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down Expand Up @@ -182,6 +184,12 @@ func validateRoleDefinitionName(i interface{}, k string) ([]string, []error) {
}

func retryRoleAssignmentsClient(scope string, name string, properties authorization.RoleAssignmentCreateParameters, meta interface{}) func() *resource.RetryError {
urlErrorIsRetryable := func(err *url.Error) bool {
if err.Temporary() || err.Timeout() {
return true
}
return false
}

return func() *resource.RetryError {
roleAssignmentsClient := meta.(*ArmClient).roleAssignmentsClient
Expand All @@ -190,7 +198,18 @@ func retryRoleAssignmentsClient(scope string, name string, properties authorizat
_, err := roleAssignmentsClient.Create(ctx, scope, name, properties)

if err != nil {
return resource.RetryableError(err)
// Error is retryable only if it is a temporary error or timeout
switch e := err.(type) {
case autorest.DetailedError:
if ue, ok := e.Original.(*url.Error); ok && urlErrorIsRetryable(ue) {
return resource.RetryableError(err)
}
case *url.Error:
if urlErrorIsRetryable(e) {
return resource.RetryableError(err)
}
}
return resource.NonRetryableError(err)
}
return nil

Expand Down

0 comments on commit 3f2d188

Please sign in to comment.