-
Notifications
You must be signed in to change notification settings - Fork 167
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: project delete function uses correct string representation of id #1733
Changes from 4 commits
1e2b606
125b59f
41d7b86
fe38dd6
ca9de68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -269,7 +269,7 @@ func (r *projectRS) Create(ctx context.Context, req resource.CreateRequest, resp | |||||
|
||||||
_, _, err := connV2.TeamsApi.AddAllTeamsToProject(ctx, project.GetId(), NewTeamRoleList(ctx, teams)).Execute() | ||||||
if err != nil { | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.Id) | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.GetId()) | ||||||
if errd != nil { | ||||||
resp.Diagnostics.AddError("error during project deletion when adding teams", fmt.Sprintf(errorProjectDelete, project.GetId(), err.Error())) | ||||||
return | ||||||
|
@@ -290,7 +290,7 @@ func (r *projectRS) Create(ctx context.Context, req resource.CreateRequest, resp | |||||
} | ||||||
_, _, err := connV2.ProjectsApi.SetProjectLimit(ctx, limit.Name.ValueString(), project.GetId(), dataFederationLimit).Execute() | ||||||
if err != nil { | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.Id) | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.GetId()) | ||||||
if errd != nil { | ||||||
resp.Diagnostics.AddError("error during project deletion when adding limits", fmt.Sprintf(errorProjectDelete, project.GetId(), err.Error())) | ||||||
return | ||||||
|
@@ -304,7 +304,7 @@ func (r *projectRS) Create(ctx context.Context, req resource.CreateRequest, resp | |||||
// add settings | ||||||
projectSettings, _, err := connV2.ProjectsApi.GetProjectSettings(ctx, *project.Id).Execute() | ||||||
if err != nil { | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.Id) | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.GetId()) | ||||||
if errd != nil { | ||||||
resp.Diagnostics.AddError("error during project deletion when getting project settings", fmt.Sprintf(errorProjectDelete, project.GetId(), err.Error())) | ||||||
return | ||||||
|
@@ -333,7 +333,7 @@ func (r *projectRS) Create(ctx context.Context, req resource.CreateRequest, resp | |||||
} | ||||||
|
||||||
if _, _, err = connV2.ProjectsApi.UpdateProjectSettings(ctx, project.GetId(), projectSettings).Execute(); err != nil { | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.Id) | ||||||
errd := deleteProject(ctx, r.Client.AtlasV2, project.GetId()) | ||||||
if errd != nil { | ||||||
resp.Diagnostics.AddError("error during project deletion when updating project settings", fmt.Sprintf(errorProjectDelete, project.GetId(), err.Error())) | ||||||
return | ||||||
|
@@ -494,7 +494,7 @@ func (r *projectRS) Delete(ctx context.Context, req resource.DeleteRequest, resp | |||||
} | ||||||
|
||||||
projectID := project.ID.ValueString() | ||||||
err := deleteProject(ctx, r.Client.AtlasV2, &projectID) | ||||||
err := deleteProject(ctx, r.Client.AtlasV2, projectID) | ||||||
|
||||||
if err != nil { | ||||||
resp.Diagnostics.AddError("error when destroying resource", fmt.Sprintf(errorProjectDelete, projectID, err.Error())) | ||||||
|
@@ -725,11 +725,11 @@ func UpdateProject(ctx context.Context, client GroupProjectService, projectState | |||||
return nil | ||||||
} | ||||||
|
||||||
func deleteProject(ctx context.Context, connV2 *admin.APIClient, projectID *string) error { | ||||||
func deleteProject(ctx context.Context, connV2 *admin.APIClient, projectID string) error { | ||||||
stateConf := &retry.StateChangeConf{ | ||||||
Pending: []string{projectDependentsStateDeleting, projectDependentsStateRetry}, | ||||||
Target: []string{projectDependentsStateIdle}, | ||||||
Refresh: resourceProjectDependentsDeletingRefreshFunc(ctx, projectID, connV2), | ||||||
Refresh: ResourceProjectDependentsDeletingRefreshFunc(ctx, projectID, ServiceFromClient(connV2)), | ||||||
Timeout: 30 * time.Minute, | ||||||
MinTimeout: 30 * time.Second, | ||||||
Delay: 0, | ||||||
|
@@ -738,10 +738,10 @@ func deleteProject(ctx context.Context, connV2 *admin.APIClient, projectID *stri | |||||
_, err := stateConf.WaitForStateContext(ctx) | ||||||
|
||||||
if err != nil { | ||||||
tflog.Info(ctx, fmt.Sprintf("[ERROR] could not determine MongoDB project %s dependents status: %s", *projectID, err.Error())) | ||||||
tflog.Info(ctx, fmt.Sprintf("[ERROR] could not determine MongoDB project %s dependents status: %s", projectID, err.Error())) | ||||||
} | ||||||
|
||||||
_, _, err = connV2.ProjectsApi.DeleteProject(ctx, *projectID).Execute() | ||||||
_, _, err = connV2.ProjectsApi.DeleteProject(ctx, projectID).Execute() | ||||||
|
||||||
return err | ||||||
} | ||||||
|
@@ -755,17 +755,16 @@ Else consider the aggregate dependents idle. | |||||
If we get a defined error response, return that right away | ||||||
Else retry | ||||||
*/ | ||||||
func resourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID *string, connV2 *admin.APIClient) retry.StateRefreshFunc { | ||||||
func ResourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID string, client GroupProjectService) retry.StateRefreshFunc { | ||||||
return func() (any, string, error) { | ||||||
nonNullProjectID := conversion.StringPtrNullIfEmpty(projectID) | ||||||
clusters, _, err := connV2.ClustersApi.ListClusters(ctx, nonNullProjectID.String()).Execute() | ||||||
clusters, _, listClustersErr := client.ListClusters(ctx, projectID) | ||||||
dependents := AtlasProjectDependants{AdvancedClusters: clusters} | ||||||
|
||||||
if _, ok := admin.AsError(err); ok { | ||||||
return nil, "", err | ||||||
if _, ok := admin.AsError(listClustersErr); ok { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this would imply removing redudant if statement below)
Suggested change
curious if we want to unify both error checks, don't see a reason why for ApiError we would return error, while for others SDK error types keep on retrying. Would simply return error for an encountered error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't want to change this to avoid changing behaviour, but I think it makes sense to unify it. |
||||||
return nil, "", listClustersErr | ||||||
} | ||||||
|
||||||
if err != nil { | ||||||
if listClustersErr != nil { | ||||||
return nil, projectDependentsStateRetry, nil | ||||||
} | ||||||
|
||||||
|
@@ -779,7 +778,7 @@ func resourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID | |||||
} | ||||||
} | ||||||
|
||||||
log.Printf("[DEBUG] status for MongoDB project %s dependents: %s", nonNullProjectID, projectDependentsStateDeleting) | ||||||
log.Printf("[DEBUG] status for MongoDB project %s dependents: %s", projectID, projectDependentsStateDeleting) | ||||||
|
||||||
return dependents, projectDependentsStateDeleting, nil | ||||||
} | ||||||
|
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.
can we have a test that fails before this change and passes after?
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.
we now have. The call we mock in the test is only mocked with correct projectId, so in case the string has extra quotes, tests fail. See image
![Screenshot 2023-12-11 at 11 14 26](https://private-user-images.githubusercontent.com/55513886/289503347-89614330-d5f7-4fe2-a4f7-928497c272cb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAwMjcwNzksIm5iZiI6MTcyMDAyNjc3OSwicGF0aCI6Ii81NTUxMzg4Ni8yODk1MDMzNDctODk2MTQzMzAtZDVmNy00ZmUyLWE0ZjctOTI4NDk3YzI3MmNiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAzVDE3MTI1OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg0NmJlYzRiNjNhNTczMjlmOTQzNDk3NjdhNDUxODM3M2JiZDQyNzg3ZGZkN2ZiYTcyMjlmMDk0ZjBjYmVjZWImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TeSFWUNJfOkDpLapyZq-LzV4LuKeIqrgnpCe8bY94Dc)
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.
great, thx!