Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if error is retryable before returning that it is #1934

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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