Skip to content

Commit

Permalink
Adding retry functionality to role assignment (#1647)
Browse files Browse the repository at this point in the history
* Adding retry functionality to role assignment

* Fixing formatting issue

* bumping the timeout to 5m
  • Loading branch information
Matt Betts authored and tombuildsstuff committed Jul 30, 2018
1 parent 79728da commit 589ac11
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion azurerm/resource_arm_role_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"log"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-01-01-preview/authorization"
"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -105,7 +107,7 @@ func resourceArmRoleAssignmentCreate(d *schema.ResourceData, meta interface{}) e
},
}

_, err := roleAssignmentsClient.Create(ctx, scope, name, properties)
err := resource.Retry(300*time.Second, retryRoleAssignmentsClient(scope, name, properties, meta))
if err != nil {
return err
}
Expand Down Expand Up @@ -176,3 +178,19 @@ func validateRoleDefinitionName(i interface{}, k string) ([]string, []error) {
}
return nil, nil
}

func retryRoleAssignmentsClient(scope string, name string, properties authorization.RoleAssignmentCreateParameters, meta interface{}) func() *resource.RetryError {

return func() *resource.RetryError {
roleAssignmentsClient := meta.(*ArmClient).roleAssignmentsClient
ctx := meta.(*ArmClient).StopContext

_, err := roleAssignmentsClient.Create(ctx, scope, name, properties)

if err != nil {
return resource.RetryableError(err)
}
return nil

}
}

0 comments on commit 589ac11

Please sign in to comment.