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

chore: Uses new Atlas Go SDK version #1831

Merged
merged 21 commits into from
Jan 15, 2024
Merged

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Jan 12, 2024

Description

Uses new Atlas Go SDK version.

The goal of this PR is to do as few changes as possible while keeping the same behavior as the current code.
Next PRs will improve update operation, createonly and readonly attributes of each TF resource using this SDK.

Link to any related issue(s): https://jira.mongodb.org/browse/CLOUDP-222424

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

@lantoli lantoli force-pushed the CLOUDP-222424_sdk_update_pointers branch from eae0000 to 25ea035 Compare January 12, 2024 15:09
@lantoli lantoli force-pushed the CLOUDP-222424_sdk_update_pointers branch from 23793e5 to 5651c2b Compare January 12, 2024 19:02
@lantoli lantoli marked this pull request as ready for review January 12, 2024 20:14
@lantoli lantoli requested a review from a team as a code owner January 12, 2024 20:14
Comment on lines 43 to 45
Roles: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasRoles(rolesModel)),
Labels: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasLabels(labelsModel)),
Scopes: conversion.NonEmptySliceToSlicePtr(NewMongoDBAtlasScopes(scopesModel)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not have the New.. function return the pointer?

Copy link
Member Author

@lantoli lantoli Jan 15, 2024

Choose a reason for hiding this comment

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

I'm trying to minimize the changes here, then there will a PR per resource to fix the update bugs, and check the readonly / createonly attributes, and improve the clarity as in your suggestion. Those changes will be more located (per resource)

Copy link
Member Author

@lantoli lantoli Jan 15, 2024

Choose a reason for hiding this comment

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

as Agusting said before we'll probably get rid of all NonEmptySliceToSlicePtr in the next PRs

@@ -216,12 +216,12 @@ func schemaOnlineArchive() map[string]*schema.Schema {
}

func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2
connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2
Copy link
Collaborator

@andreaangiolillo andreaangiolillo Jan 15, 2024

Choose a reason for hiding this comment

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

Could we use the name v20231001002AtlasSDK instead of OldAtlasV2? It is not easy to understand what we consider the old atlas v2. In addition, the new name will allow us to support multiple older versions if needed

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm following the convention @oarbusi did in his previous PR, e.g. it's being used in federated_settings_identity_provider service

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed that PR 😭 What is our opinion on the name used for the Atlas SDK?

Copy link
Member Author

@lantoli lantoli Jan 15, 2024

Choose a reason for hiding this comment

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

maybe it's not the best name but I couldn't find a better name to suggest, the idea is that it's an SDK a little older than the current one used in most places.
also the idea is that this old SDK is only used until the corresponding service team fixes their API so use of this old sdk should be short duration

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the correct naming would include the dates to avoid confusion if more parallel sdks are mantained

Copy link
Member Author

@lantoli lantoli Jan 15, 2024

Choose a reason for hiding this comment

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

right now I think it's a premature optimization as we only have 2 sdks, y we intend to have the old one a short period of time. if more than 2 would be needed at some moment then I agree.

Copy link
Member Author

Choose a reason for hiding this comment

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

at the end I've added the date to the old sdk as per your recommendation

@@ -56,3 +56,10 @@ func IsStringPresent(strPtr *string) bool {
func MongoDBRegionToAWSRegion(region string) string {
return strings.ReplaceAll(strings.ToLower(region), "_", "-")
}

func NonEmptySliceToSlicePtr[T any](v []T) *[]T {
Copy link
Collaborator

@gssbzn gssbzn Jan 15, 2024

Choose a reason for hiding this comment

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

if slices only let's be more correct about it

Suggested change
func NonEmptySliceToSlicePtr[T any](v []T) *[]T {
func NonEmptySliceToSlicePtr[S ~[]E, E any]](v S) *S {

Copy link
Member Author

Choose a reason for hiding this comment

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

name changed to NonEmptyToPtr as it might called for slices or also arrays.

internal/service/atlasuser/data_source_atlas_users_test.go Outdated Show resolved Hide resolved
@@ -216,12 +216,12 @@ func schemaOnlineArchive() map[string]*schema.Schema {
}

func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2
connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the correct naming would include the dates to avoid confusion if more parallel sdks are mantained

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 besides pending comments

@@ -56,3 +56,10 @@ func IsStringPresent(strPtr *string) bool {
func MongoDBRegionToAWSRegion(region string) string {
return strings.ReplaceAll(strings.ToLower(region), "_", "-")
}

func NonEmptySliceToSlicePtr[T any](v []T) *[]T {
Copy link
Member

Choose a reason for hiding this comment

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

we will likely have a similar approach in CFN and CLI for this version upgrade, could be worth incorporating within SDK as a helper function and mention in upgrade guide.

Copy link
Member Author

Choose a reason for hiding this comment

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

@gssbzn what do you think?

on the other hand I think I'll be able to delete most of the uses of this function in next PRs

@@ -31,7 +31,7 @@ var (
type MongoDBClient struct {
Atlas *matlasClient.Client
AtlasV2 *atlasSDK.APIClient
OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider resource. Will be removed in terraform-provider-1.16.0
OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider and online_archive resources. Will be removed in terraform-provider-1.16.0
Copy link
Member Author

Choose a reason for hiding this comment

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

@andreaangiolillo @AgustinBettati @gssbzn I've added online_archive to the old sdk comment. but I would prefer to keep this PR changes as small as possible, I think old sdk renaming belongs to a different PR, it would affect client file and federated files apart from online_archive.

Copy link
Member Author

Choose a reason for hiding this comment

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

@andreaangiolillo @AgustinBettati @gssbzn hey, at the end I've added the date to old sdk in this PR in case you want to take a look. thanks

@marcosuma
Copy link
Collaborator

LGTM on my side, will wait once the comments are addressed.

@lantoli lantoli merged commit 02281f2 into master Jan 15, 2024
33 checks passed
@lantoli lantoli deleted the CLOUDP-222424_sdk_update_pointers branch January 15, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants