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

feat: search node management with mongodbatlas_search_deployment resource and data source #1633

Merged
merged 16 commits into from
Nov 17, 2023

Conversation

AgustinBettati
Copy link
Member

Description

Jira tickets: INTMDB-1273, INTMDB-1257

Includes change from #1621 and #1609.

This PR is using the latest SDK release, and adjusting documentation links.

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

go-version-file: 'go.mod'
- name: Acceptance Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
Copy link
Member

Choose a reason for hiding this comment

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

CI: true is missing ;-). cc @marcosuma

Copy link
Member Author

Choose a reason for hiding this comment

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

true, however that env variable is not used in this job as no tests need to be skipped (several jobs dont define it). Can add just for consistency.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, i know it's only used when calling SkipTestForCI , it was more to advocate for a common env zone :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

will try to answer to your PR :) but I think the global env variables would make the opposite effect here when you create a new job and you don't immediately expect there are global variables that might affect this job's behaviour

Copy link
Member

Choose a reason for hiding this comment

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

or it could be the opposite, that you try to use SkipTestForCI and don't know why it's not skipping it.

I think it depends on the expectations set on the tests run from that GH action. for me it's clear in this case that all tests "want" to have CI:true even if they don't use/need it right now.

Comment on lines +191 to +195
updateTimeout, diags := searchDeploymentPlan.Timeouts.Update(ctx, defaultSearchNodeTimeout)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this is more or less the same that is in create any chance we could make this method leaner and move this inside the waitSearch...? or just make it a separate method with a one-liner call here..

Copy link
Member Author

Choose a reason for hiding this comment

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

So there are some details here to take into account:

  • for the simple approach of extracting to separate methods and having a one-liner: the part checking if there are errors and finish the update function (L193-L195) can not be extracted. L192 could potentially be extracted into separate function, but not in favour of passing resp and mutating within another function (harder to follow).
  • for having the logic inside waitSearch function, an additional parameter would be added to receive the function searchDeploymentPlan.Timeouts.Create and searchDeploymentPlan.Timeouts.Update which add some complexity to the method signature. This is why I end up passing timeout time.Duration directly with some common code in each method.

Copy link
Member Author

Choose a reason for hiding this comment

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

moving forward with the merge, if any further action comes from this comment we can address in a followup PR.

Comment on lines +298 to +316
deploymentResp, resp, err := client.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute()
if err != nil && deploymentResp == nil && resp == nil {
return nil, "", err
}
if err != nil {
if resp.StatusCode == 400 && strings.Contains(err.Error(), searchDeploymentDoesNotExistsError) {
return "", retrystrategy.RetryStrategyDeletedState, nil
}
if resp.StatusCode == 503 {
return "", retrystrategy.RetryStrategyPendingState, nil
}
return nil, "", err
}

if util.IsStringPresent(deploymentResp.StateName) {
tflog.Debug(ctx, fmt.Sprintf("search deployment status: %s", *deploymentResp.StateName))
return deploymentResp, *deploymentResp.StateName, nil
}
return deploymentResp, "", nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, this could have been so perfectly unit tested... can't wait to see them 😛

Copy link
Collaborator

@marcosuma marcosuma left a comment

Choose a reason for hiding this comment

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

few comments, LGMT overall!

Copy link
Contributor

Code Coverage

Package Line Rate Health
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 2%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator 68%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/testutils 46%
github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/util 17%
Summary 3% (284 / 10548)

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