From 3d4601268478fa7d2f4e6a9f4e1aedbd1db88ade Mon Sep 17 00:00:00 2001 From: Joakim Bakke Hellum Date: Wed, 25 Jul 2018 17:30:27 +0200 Subject: [PATCH] retry role assignment creation --- azurerm/resource_arm_role_assignment.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_role_assignment.go b/azurerm/resource_arm_role_assignment.go index 113c57dd04de..26b96a8e0375 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,9 +107,16 @@ func resourceArmRoleAssignmentCreate(d *schema.ResourceData, meta interface{}) e }, } - _, err := roleAssignmentsClient.Create(ctx, scope, name, properties) - if err != nil { - return err + retryError := resource.Retry(120*time.Second, func() *resource.RetryError { + _, err := roleAssignmentsClient.Create(ctx, scope, name, properties) + if err != nil { + return resource.RetryableError(err) + } + return nil + }) + + if retryError != nil { + return fmt.Errorf("Error creating Role Assignment %s: %s", name, retryError) } read, err := roleAssignmentsClient.Get(ctx, scope, name)