From 589ac116591af8d7c0dc4bf526e118dec17a37ee Mon Sep 17 00:00:00 2001 From: Matt Betts Date: Mon, 30 Jul 2018 09:59:48 -0400 Subject: [PATCH] Adding retry functionality to role assignment (#1647) * Adding retry functionality to role assignment * Fixing formatting issue * bumping the timeout to 5m --- azurerm/resource_arm_role_assignment.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_role_assignment.go b/azurerm/resource_arm_role_assignment.go index 113c57dd04de..e9f6d307d28b 100644 --- a/azurerm/resource_arm_role_assignment.go +++ b/azurerm/resource_arm_role_assignment.go @@ -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" ) @@ -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 } @@ -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 + + } +}