Skip to content

Commit

Permalink
use wait timeout from ctx for pim role assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Jul 26, 2023
1 parent 5279781 commit 1684e75
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (r PimEligibleRoleAssignmentResource) Create() sdk.ResourceFunc {
Target: []string{"Created"},
Refresh: createEligibilityRoleAssignment(ctx, clientRequest, requestId, &payload),
MinTimeout: 30 * time.Second,
Timeout: 5 * time.Minute,
Timeout: waitTimeoutFromCtx(ctx, 10*time.Minute),
}
if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
Expand All @@ -219,7 +219,7 @@ func (r PimEligibleRoleAssignmentResource) Create() sdk.ResourceFunc {
Target: []string{"Found"},
Refresh: waitForEligibleRoleAssignmentSchedule(ctx, clientInstances, config.Scope, config.PrincipalId, config.RoleDefinitionId, "Found"),
MinTimeout: 30 * time.Second,
Timeout: 5 * time.Minute,
Timeout: waitTimeoutFromCtx(ctx, 10*time.Minute),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand Down Expand Up @@ -344,7 +344,7 @@ func (PimEligibleRoleAssignmentResource) Delete() sdk.ResourceFunc {
Target: []string{"Deleted"},
Refresh: deleteEligibilityRoleAssignmentSchedule(ctx, clientRequest, deleteId, &payload),
MinTimeout: 1 * time.Minute,
Timeout: 5 * time.Minute,
Timeout: waitTimeoutFromCtx(ctx, 5*time.Minute),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand All @@ -357,7 +357,7 @@ func (PimEligibleRoleAssignmentResource) Delete() sdk.ResourceFunc {
Target: []string{"Missing"},
Refresh: waitForEligibleRoleAssignmentSchedule(ctx, clientInstances, id.Scope, id.PrincipalId, id.RoleDefinitionId, "Missing"),
MinTimeout: 30 * time.Second,
Timeout: 5 * time.Minute,
Timeout: waitTimeoutFromCtx(ctx, 5*time.Minute),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand Down Expand Up @@ -653,3 +653,10 @@ func deleteEligibilityRoleAssignmentSchedule(ctx context.Context, client *roleel
return result, "Deleted", nil
}
}

func waitTimeoutFromCtx(ctx context.Context, defaultValue time.Duration) time.Duration {
if deadline, ok := ctx.Deadline(); ok {
defaultValue = time.Until(deadline)
}
return defaultValue
}

0 comments on commit 1684e75

Please sign in to comment.