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

fix: project delete function uses correct string representation of id #1733

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

oarbusi
Copy link
Collaborator

@oarbusi oarbusi commented Dec 11, 2023

Description

Project delete was using wrong string representation of Id, with quotes ("projectId") instead of plain string (projectId).

Within our project delete function we have a logic that waits for all "dependants" to be deleted.
During the SDK migration there was a change with how to obtain the project id that is used to list the cluster of a project, which is now passing an incorrect value. This API call uses nonNullProjectID of type types.String, so nonNullProjectID.String() was responding with "6575af27f93c7a6a4b50b239" resulting in an error by the SDK: "groupId must have less than 24 elements”. Due to whats seems like incorrect logic, this error simply lead to retrying constantly until eventually the timeout is reached.

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contribution guidelines
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals, I defined an isolated PR with a relevant title as it will be used in the auto-generated changelog.

Further comments

@github-actions github-actions bot added the bug label Dec 11, 2023
@@ -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())
Copy link
Member

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?

Copy link
Collaborator Author

@oarbusi oarbusi Dec 11, 2023

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

Copy link
Member

Choose a reason for hiding this comment

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

great, thx!

@oarbusi oarbusi marked this pull request as ready for review December 11, 2023 10:19
@oarbusi oarbusi requested a review from a team as a code owner December 11, 2023 10:19
Copy link
Member

@AgustinBettati AgustinBettati left a comment

Choose a reason for hiding this comment

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

LGTM, one change to consider

dependents := AtlasProjectDependants{AdvancedClusters: clusters}

if _, ok := admin.AsError(err); ok {
return nil, "", err
if _, ok := admin.AsError(listClustersErr); ok {
Copy link
Member

Choose a reason for hiding this comment

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

(this would imply removing redudant if statement below)

Suggested change
if _, ok := admin.AsError(listClustersErr); ok {
if listClustersErr != nil {

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion 31%
github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema 100%
github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate 68%
github.com/mongodb/terraform-provider-mongodbatlas/internal/provider 7%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/accesslistapikey 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration 33%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/apikey 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/atlasuser 0%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/auditing 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/backupcompliancepolicy 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupschedule 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshot 5%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotexportbucket 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotexportjob 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupsnapshotrestorejob 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudprovideraccess 4%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/clusteroutagesimulation 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/customdbrole 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/customdnsconfigurationclusteraws 5%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser 0%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/datalakepipeline 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest 0%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/eventtrigger 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federateddatabaseinstance 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedquerylimit 4%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsidentityprovider 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgconfig 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/federatedsettingsorgrolemapping 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/globalclusterconfig 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/ldapconfiguration 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/ldapverify 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/maintenancewindow 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/networkcontainer 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/networkpeering 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/onlinearchive 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/organization 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/orginvitation 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privateendpointregionalmode 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpoint 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpointserverless 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpointservice 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpointservicedatafederationonlinearchive 3%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpointserviceserverless 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project 30%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectapikey 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectinvitation 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectipaccesslist 0%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/rolesorgid 7%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment 23%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchindex 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/serverlessinstance 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streaminstance 14%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/teams 1%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/thirdpartyintegration 4%
github.com/mongodb/terraform-provider-mongodbatlas/internal/service/x509authenticationdatabaseuser 2%
github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc 4%
Summary 5% (588 / 10841)

@oarbusi oarbusi merged commit 5c1bebd into master Dec 11, 2023
30 checks passed
@oarbusi oarbusi deleted the fix-project-delete branch December 11, 2023 14:08
lantoli added a commit that referenced this pull request Dec 12, 2023
* master:
  fix: project delete function uses correct string representation of id (#1733)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants