Skip to content

fix: Provide err when error message populated in mongodbatlas_privatelink_endpoint and mongodbatlas_privatelink_endpoint_service #2803

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

Merged

Conversation

cveticm
Copy link
Contributor

@cveticm cveticm commented Nov 15, 2024

Description

Both mongodbatlas_privatelink_endpoint_service and mongodbatlas_privatelink_endpoint have a error_message computed attribute (present in GET response), however no error message is being created to make users aware of the error when it is present. This PR adds the necessary logic to inform the user when an error is present.

  • Within the mongodbatlas_privatelink_endpoint_service, a testcase, TestAccNetworkRSPrivateLinkEndpointServiceAWS_Failed, has been added to verify error is now received.
    This test passes an invalid vcpe id to a mongodbatlas_privatelink_endpoint_service resource. Creation will succeed but GET requests will fail with Interface endpoint <invalid_vcpe_id> was not found

  • A testcase within mongodbatlas_privatelink_endpoint was not found and, hence, no test has been added.

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

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

@github-actions github-actions bot added the bug label Nov 15, 2024
@cveticm cveticm added enhancement and removed bug labels Nov 15, 2024
@github-actions github-actions bot added bug and removed enhancement labels Nov 15, 2024
Comment on lines +228 to +230
if privateEndpoint.GetErrorMessage() != "" {
return diag.FromErr(fmt.Errorf("privatelink endpoint is in a failed state: %s", privateEndpoint.GetErrorMessage()))
}
Copy link
Contributor Author

@cveticm cveticm Nov 15, 2024

Choose a reason for hiding this comment

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

It is possible that this fix might not be touched ever. Given that only 3 fields (bar timeout) can be modified for this resource, the only failure I can conceive of which would allow for a successful POST and error in GET is an unexpected error from Atlas or the cloud provider. Further investigation would be needed to verify this.

As it's a simple fix which adds minimal computation time, I suggest keeping the fix in the case a scenario is revealed to trigger this code to save the user from a silent fail.

Copy link
Collaborator

@EspenAlbert EspenAlbert Nov 18, 2024

Choose a reason for hiding this comment

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

Uncertain about raising an error here, I think a warning might be more appropriate?
What is the UX if the error is raised? Is there anything they can do other than terraform state rm or terraform destroy to get to a working state again?
I think this might fail on every plan after the error_message is populated in backend response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To my knowledge, there isn't an alternative for UX other than destroying the resource as the API don't have a PATCH endpoint to update this resource. I think this might make an error appropriate. WDYT @EspenAlbert ?

Config: configFailAWS(
awsAccessKey, awsSecretKey, projectID, providerName, region, resourceSuffix,
),
Check: resource.TestCheckResourceAttr(resourceName, "error_message", "privatelink endpoint is in a failed state: Interface endpoint vpce-11111111111111111 was not found."),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check error_message field has been properly populated

Copy link
Member

@lantoli lantoli Nov 18, 2024

Choose a reason for hiding this comment

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

if plan or apply fails, is it useful to have this attribute error_message that won't be able to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lantoli, I'm not sure I fully understand. This fix is to ensure error_message is populated in the case that creation is successful but the proceeding GET returns a fail state. In the case that plan fails or apply fails during creation, an alternative error is provided. Could you clarify your comment?

Copy link
Member

@lantoli lantoli Nov 19, 2024

Choose a reason for hiding this comment

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

sorry, maybe I'm not understanding this test. Is the Check useful in the test when we also have a ExpectError? We are expecting an error, so for ExpectError to pass the plan or apply must fail, so in that case I think it doesn't matter what the attribute values are as it failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, the check is more to outline that the error_message field has been correctly populated but ultimately isn't needed in this test since we expect an error. This check can be removed.

@cveticm cveticm marked this pull request as ready for review November 15, 2024 16:47
@cveticm cveticm requested review from a team as code owners November 15, 2024 16:47
Copy link
Contributor

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

Copy link
Collaborator

@andreaangiolillo andreaangiolillo 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

@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, great that you managed to capture in a test 💯 Left follow up doubt in case we can leave it running in CI.

@@ -17,6 +18,37 @@ func TestAccNetworkRSPrivateLinkEndpointServiceAWS_Complete(t *testing.T) {
resource.Test(t, *testCase)
}

func TestAccNetworkRSPrivateLinkEndpointServiceAWS_Failed(t *testing.T) {
acc.SkipTestForCI(t) // needs AWS configuration
Copy link
Member

@AgustinBettati AgustinBettati Nov 15, 2024

Choose a reason for hiding this comment

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

nit: Is it possible this test can be enabled in the CI? Don't see any particular pre-requisite AWS resources being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks for pointing out AWS provider was not needed! Removed CI skip 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test now runs successfully in CI

Copy link
Member

Choose a reason for hiding this comment

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

great that it runs in CI 👏

Copy link
Contributor

@carriecwk carriecwk left a comment

Choose a reason for hiding this comment

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

LGTM!

@cveticm cveticm merged commit 5080ffa into master Nov 20, 2024
38 checks passed
@cveticm cveticm deleted the CLOUDP-282564-provide-err-when-error_message-populated branch November 20, 2024 10:36
svc-apix-Bot added a commit that referenced this pull request Nov 20, 2024
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.

6 participants