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

azurerm_pim_eligible_role_assignment: use timeout from ctx instead of a fix value #22682

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this default value will never get used - ctx's should always be wrapped by a timeout, so can we remove this method and instead use:

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

// ...
Timeout: time.Until(deadline),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes seanse. updated in this way.

if deadline, ok := ctx.Deadline(); ok {
defaultValue = time.Until(deadline)
}
return defaultValue
}