-
Notifications
You must be signed in to change notification settings - Fork 188
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
fix: Avoids error when removing project api key assignment for deleted project #1641
Conversation
@@ -396,30 +399,30 @@ func newProjectAssignment(ctx context.Context, conn *matlas.Client, apiKeyID str | |||
return results, nil | |||
} | |||
|
|||
func getStateProjectAssignmentAPIKeys(d *schema.ResourceData) (newAPIKeys, changedAPIKeys, removedAPIKeys []any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes in this function are only renaming variables
|
projectID := apiKey.(map[string]any)["project_id"].(string) | ||
_, err := conn.ProjectAPIKeys.Unassign(ctx, projectID, apiKeyID) | ||
if err != nil && strings.Contains(err.Error(), "GROUP_NOT_FOUND") { | ||
continue // allows removing assignment for a project that has been deleted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would normally avoid continue in this situation, although your solution is probably more clear than:
if err != nil {
if !strings.Contains(err.Error(), "GROUP_NOT_FOUND") { // allows removing assignment for a project that has been deleted
return diag.Errorf("error removing api_key(%s) from the project(%s): %s", apiKeyID, projectID, err)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, went for this approach to make this case explicit and easy to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
knitpit for changelog in PR title:
fix: avoid error when removing project api key... =>
fix: Avoids error when removing project api key...
Description
Link to any related issue(s): INTMDB-1297
Enables deleting a project and is project_assignment in project_api_key resource without encountering errors. This is only one part of HELP-52313.
Type of change:
Required Checklist:
Further comments