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: Handles resource deletion in ReadResource #2268

Merged
merged 15 commits into from May 22, 2024

Conversation

EspenAlbert
Copy link
Collaborator

Description

Handles resource deletion in ReadResource.
Terraform informs you about the resource deleted outside of Terraform, and the plan will re-create the resource

Link to any related issue(s): CLOUDP-248670

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

@github-actions github-actions bot added the bug label May 10, 2024
Copy link
Contributor

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

@github-actions github-actions bot added the stale label May 16, 2024
@EspenAlbert EspenAlbert added the not_stale Not stale issue or PR label May 16, 2024
@EspenAlbert EspenAlbert marked this pull request as ready for review May 20, 2024 08:40
@EspenAlbert EspenAlbert requested review from a team as code owners May 20, 2024 08:40
Copy link
Contributor

APIx bot: a message has been sent to Docs Slack channel

@@ -289,8 +289,12 @@ func (r *encryptionAtRestRS) Read(ctx context.Context, req resource.ReadRequest,

connV2 := r.Client.AtlasV2

encryptionResp, _, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute()
encryptionResp, getResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
encryptionResp, getResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute()
encryptionResp, resp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute()

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

resp is already defined in the method signature:

func (r *encryptionAtRestRS) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse)

if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
d.SetId("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why in here we don't do resp.State.RemoveResource(ctx) ?

Copy link
Member

@lantoli lantoli May 20, 2024

Choose a reason for hiding this comment

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

same question, what is it for and why we use it only in some resources. do we also need to call d.SetId("") when calling RemoveResource?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the difference between SDK v2 and TPF in how we mark a resource as deleted, see google doc

Copy link
Contributor

@kanchana-mongodb kanchana-mongodb left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@lantoli lantoli left a comment

Choose a reason for hiding this comment

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

thanks for your patience :-)

Copy link
Contributor

@kanchana-mongodb kanchana-mongodb left a comment

Choose a reason for hiding this comment

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

1 non-blocking suggestion. LGTM.

.changelog/2268.txt Outdated Show resolved Hide resolved
.changelog/2268.txt Outdated Show resolved Hide resolved
@@ -0,0 +1,23 @@
```release-note:bug
resource/cloud_backup_schedule: Fixes behavior when resource is deleted outside of Terraform.
Copy link
Member

Choose a reason for hiding this comment

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

@AgustinBettati should changelog sentences end in period? I see most of them don't have it, but some of them have it like https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/.changelog/2208.txt

Copy link
Member

@lantoli lantoli May 21, 2024

Choose a reason for hiding this comment

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

looking at: https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/CHANGELOG.md
it looks like it would be better NOT to have periods at the end, as the after the sentence it's the associated PR link

Copy link
Member

@lantoli lantoli May 21, 2024

Choose a reason for hiding this comment

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

@EspenAlbert apart from removing periods note that resources should have mongodbatlas_ as prefix, e.g.: resource/mongodbatlas_cloud_backup_schedule: ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forgot to refresh the PR 🤦, and merged this. I'll create a follow up PR to remove the trailing dot and ensure the prefix

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@lantoli and @AgustinBettati updated in follow-up PR: #2298

@EspenAlbert EspenAlbert merged commit ae63d9e into master May 22, 2024
31 of 32 checks passed
@EspenAlbert EspenAlbert deleted the CLOUDP-248670_read_resource_support_404 branch May 22, 2024 06:42
@EspenAlbert
Copy link
Collaborator Author

Only OUT_OF_CAPACITY failure in the test so merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug not_stale Not stale issue or PR stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants