Skip to content

Commit

Permalink
Merge pull request #22682 from wuxu92/pimrole/timeout
Browse files Browse the repository at this point in the history
`azurerm_pim_eligible_role_assignment`: use timeout from `ctx` instead of a fix value
  • Loading branch information
tombuildsstuff authored Jul 26, 2023
2 parents 999a674 + a3a6491 commit 5269adb
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,18 @@ func (r PimEligibleRoleAssignmentResource) Create() sdk.ResourceFunc {
}

requestId := roleeligibilityschedulerequests.NewScopedRoleEligibilityScheduleRequestID(config.Scope, uuid)

deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal error: context has no deadline")
}

stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Missing"},
Target: []string{"Created"},
Refresh: createEligibilityRoleAssignment(ctx, clientRequest, requestId, &payload),
MinTimeout: 30 * time.Second,
Timeout: 5 * time.Minute,
Timeout: time.Until(deadline),
}
if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for %s to be created: %+v", id, err)
Expand All @@ -219,7 +225,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: time.Until(deadline),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand Down Expand Up @@ -338,13 +344,18 @@ func (PimEligibleRoleAssignmentResource) Delete() sdk.ResourceFunc {
}
deleteId := roleeligibilityschedulerequests.NewScopedRoleEligibilityScheduleRequestID(id.Scope, uuid)

deadline, ok := ctx.Deadline()
if ok {
return fmt.Errorf("internal error: context has no deadline")
}

// wait for resource to deleted
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Exist"},
Target: []string{"Deleted"},
Refresh: deleteEligibilityRoleAssignmentSchedule(ctx, clientRequest, deleteId, &payload),
MinTimeout: 1 * time.Minute,
Timeout: 5 * time.Minute,
Timeout: time.Until(deadline),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand All @@ -357,7 +368,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: time.Until(deadline),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
Expand Down

0 comments on commit 5269adb

Please sign in to comment.