Visitar URL original
fix: Treat 404 as success on database user delete by oarbusi · Pull Request #4777 · mongodb/terraform-provider-mongodbatlas · GitHub
Skip to content

fix: Treat 404 as success on database user delete - #4777

Merged
oarbusi merged 4 commits into
masterfrom
CLOUDP-436853
Oct 5, 2026
Merged

oarbusi merged 4 commits into
masterfrom
CLOUDP-436853

Conversation

@oarbusi

@oarbusi oarbusi commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Deleting mongodbatlas_database_user when the user is already gone from Atlas returned 404 USER_NOT_FOUND and failed the whole run. The delete had already achieved its goal, so this is success, not failure, matching the HashiCorp recommendation for resource deletes.

This PR fixes it for database_user first, with the 404 handling extracted into a shared helper (internal/common/deletenotfound.IsNotFound) so follow-up resources can adopt the same pattern, including the resources that today only tolerate a 404 in the post-delete poll. The tolerated 404 case is logged so it can be observed in production.

Link to any related issue(s):

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. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • 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 fix and verified my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

A 404 can also mean a mistaken project ID or credentials scoped differently; previously the error surfaced that, now the resource is silently dropped from state and the mistake appears later as drift. This trade-off was accepted in the ticket triage ("we only turn failure into success operations"), and the tflog line makes the tolerated case observable.

Deleting a database user that is already gone from Atlas returned 404 and
failed the whole run. The delete achieved its goal, so it now succeeds and
the resource is removed from state.

Adds internal/common/deletenotfound with shared 404 handling and logging,
to be adopted by the remaining resources in follow-up work. Documents the
deletion behavior for database user.
@oarbusi oarbusi changed the title Treat 404 as success on database user delete fix: Treat 404 as success on database user delete Oct 1, 2026
@github-actions github-actions Bot added the bug label Oct 1, 2026
@oarbusi
oarbusi marked this pull request as ready for review October 1, 2026 13:59
@oarbusi
oarbusi requested a review from a team as a code owner October 1, 2026 13:59
Copilot AI balanced review requested due to automatic review settings October 1, 2026 13:59
@augmentcode

augmentcode Bot commented Oct 1, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR makes deletion of an already-absent MongoDB Atlas database user succeed rather than fail Terraform.

Changes:

  • Adds a shared deletenotfound.IsNotFound helper that identifies errored HTTP 404 delete responses and logs the tolerated case.
  • Updates mongodbatlas_database_user deletion to use that helper while preserving diagnostics for all other errors.
  • Adds focused unit coverage for 404, non-404, successful, and nil-response cases.

Technical Notes: Transport failures and other API errors remain failures; only a 404 accompanied by an error is treated as a successful, idempotent delete.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A required changelog entry and resource-level regression coverage are missing.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Updates database-user deletion to treat Atlas 404 responses as successful, supporting idempotent Terraform destroys.

Changes:

  • Adds shared, logged 404-delete handling.
  • Applies it to database-user deletion.
  • Adds helper unit tests.
File Description
internal/​service/​databaseuser/​resource_database_user.go Tolerates 404 responses during deletion.
internal/​common/​deletenotfound/​deletenotfound.go Adds shared not-found handling and logging.
internal/​common/​deletenotfound/​deletenotfound_test.go Tests response classification.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/service/databaseuser/resource_database_user.go
Comment thread internal/service/databaseuser/resource_database_user.go

@AgustinBettati AgustinBettati left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Can be good to capture what are follow up plans for addressing other resources.

@oarbusi

oarbusi commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

@AgustinBettati created CLOUDP-453232 for the followup work

@oarbusi
oarbusi merged commit c3bdb08 into master Oct 5, 2026
58 checks passed
@oarbusi
oarbusi deleted the CLOUDP-436853 branch October 5, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants