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

Added poller to check for consistency on role assignment creation #6925

Merged
merged 2 commits into from May 14, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,6 +1,7 @@
package authorization

import (
"context"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -156,7 +157,6 @@ func resourceArmRoleAssignmentCreate(d *schema.ResourceData, meta interface{}) e
if err := resource.Retry(300*time.Second, retryRoleAssignmentsClient(d, scope, name, properties, meta)); err != nil {
return err
}

read, err := roleAssignmentsClient.Get(ctx, scope, name)
if err != nil {
return err
Expand All @@ -165,6 +165,23 @@ func resourceArmRoleAssignmentCreate(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Cannot read Role Assignment ID for %q (Scope %q)", name, scope)
}

stateConf := &resource.StateChangeConf{
Pending: []string{
"pending",
},
Target: []string{
"ready",
},
Refresh: roleAssignmentCreateStateRefreshFunc(ctx, roleAssignmentsClient, *read.ID),
MinTimeout: 5 * time.Second,
ContinuousTargetOccurence: 5,
Timeout: d.Timeout(schema.TimeoutCreate),
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("failed waiting for Role Assignment %q: %+v", name, err)
jackofallops marked this conversation as resolved.
Show resolved Hide resolved
}

d.SetId(*read.ID)
return resourceArmRoleAssignmentRead(d, meta)
}
Expand Down Expand Up @@ -282,3 +299,16 @@ func parseRoleAssignmentId(input string) (*roleAssignmentId, error) {
}
return &id, nil
}

func roleAssignmentCreateStateRefreshFunc(ctx context.Context, client *authorization.RoleAssignmentsClient, roleID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := client.GetByID(ctx, roleID)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return resp, "pending", nil
}
return resp, "failed", err
}
return resp, "ready", nil
}
}