-
Notifications
You must be signed in to change notification settings - Fork 189
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
fix: Provide err when error message populated in mongodbatlas_privatelink_endpoint
and mongodbatlas_privatelink_endpoint_service
#2803
Conversation
if privateEndpoint.GetErrorMessage() != "" { | ||
return diag.FromErr(fmt.Errorf("privatelink endpoint is in a failed state: %s", privateEndpoint.GetErrorMessage())) | ||
} |
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.
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.
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.
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
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.
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."), |
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.
Check error_message field has been properly populated
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.
if plan or apply fails, is it useful to have this attribute error_message that won't be able to be used?
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.
@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?
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.
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.
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.
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.
APIx bot: a message has been sent to Docs Slack channel |
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.
LGTM
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.
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 |
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.
nit: Is it possible this test can be enabled in the CI? Don't see any particular pre-requisite AWS resources being used.
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.
Yes, thanks for pointing out AWS provider was not needed! Removed CI skip 👍
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.
Test now runs successfully in CI
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 that it runs in CI 👏
internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go
Outdated
Show resolved
Hide resolved
internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go
Outdated
Show resolved
Hide resolved
internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go
Show resolved
Hide resolved
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.
LGTM!
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 withInterface 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:
Required Checklist:
Further comments