Skip to content

INTMDB-227:Create new Resource and Datasource for Serverless Instance #585

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
merged 11 commits into from
Oct 28, 2021

Conversation

abner-dou
Copy link
Contributor

@abner-dou abner-dou commented Oct 14, 2021

Description

Added new resource mongodbatlas_serverless_instance and datasources mongodbatlas_serverless_instances and mongodbatlas_serverless_instances.

New documentation was added

Link to any related issue(s):INTMDB-227

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the Terraform contribution guidelines
  • 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

Further comments

@abner-dou abner-dou added the run-testacc To run acceptance tests label Oct 14, 2021
@abner-dou abner-dou self-assigned this Oct 14, 2021
@themantissa
Copy link
Collaborator

@abner-dou not sure what happened here with the tests?

@abner-dou
Copy link
Contributor Author

abner-dou commented Oct 14, 2021

@themantissa I cancelled the acctest because I'm running the same test on my other PR, I will resume the acctest for this when the other finishes

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

Comment on lines 41 to 46
options := &matlas.ListOptions{
/* PageNum: d.Get("page_num").(int),
ItemsPerPage: d.Get("items_per_page").(int),

*/
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[q] I am not sure why these lines are commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to delete it

Comment on lines +35 to +39
projectID, projectIDOK := d.GetOk("project_id")

if !(projectIDOK) {
return diag.Errorf("project_id must be configured")
}
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
projectID, projectIDOK := d.GetOk("project_id")
if !(projectIDOK) {
return diag.Errorf("project_id must be configured")
}
projectID, err := d.GetOk("project_id")
if !(err) {
return diag.Errorf("project_id must be configured")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just following the naming convention used in the provider for this cases, but I can change it this way

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess projectIDOK it's fine since it's a boolean, and not an error

Copy link
Contributor

Choose a reason for hiding this comment

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

My only concern here is that variable is only used on that single if, don't know if you can actually reduce it to a one liner and assign on true, return error if false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the thing is, I need the other asigned variable projectID in order to be use on the rest of the function, if I use a single if line with the declaration, I will need to call again to the d.GetOk to obtain the value

}
}

return serverlessInstancesMap, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

You can rewrite this as len(serverlessInstances) > 0 and return nil, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this condition is already in line 65

if len(serverlessInstances) == 0 {
		return nil, nil
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but there's more flow to this

	if len(serverlessInstances) >  0 {

	  var serverlessInstancesMap []map[string]interface{}
          serverlessInstancesMap = make([]map[string]interface{}, len(serverlessInstances))

	for i := range serverlessInstances {
		serverlessInstancesMap[i] = map[string]interface{}{
			"connection_strings_standard_srv": serverlessInstances[i].ConnectionStrings.StandardSrv,
			"create_date":                     serverlessInstances[i].CreateDate,
			"id":                              serverlessInstances[i].ID,
			"links":                           flattenLinks(serverlessInstances[i].Links),
			"mongo_db_version":                serverlessInstances[i].MongoDBVersion,
			"name":                            serverlessInstances[i].Name,
			"provider_settings_backing_provider_name": serverlessInstances[i].ProviderSettings.BackingProviderName,
			"provider_settings_region_name":           serverlessInstances[i].ProviderSettings.RegionName,
			"provider_settings_provider_name":         serverlessInstances[i].ProviderSettings.ProviderName,
			"state_name":                              serverlessInstances[i].StateName,
		}
		return serverlessInstancesMap , nil 
	}
return nil, nil

	

Copy link
Contributor

Choose a reason for hiding this comment

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

Also why are we returning an error where is none?

}

if enableBetaFeatures := os.Getenv("MONGODB_ATLAS_ENABLE_BETA"); enableBetaFeatures == "true" {
resourcesMap["mongodbatlas_serverless_instance"] = resourceMongoDBAtlasServerlessInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a function to add all beta features?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a new function to set only beta features already added

"mongodbatlas_cloud_backup_schedule": resourceMongoDBAtlasCloudBackupSchedule(),
},
if enableBetaFeatures := os.Getenv("MONGODB_ATLAS_ENABLE_BETA"); enableBetaFeatures == "true" {
dataSourcesMap["mongodbatlas_serverless_instance"] = dataSourceMongoDBAtlasServerlessInstance()
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, maybe we can just add a single function to add both, and receives dataSourcesMap and resourcesMap

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm disregard this comment, just add a variable for MONGODB_ATLAS_ENABLE_BETA in the init of the package, set it to true if it's set to true

}
}

func resourceMongoDBAtlasServerlessInstanceUpdate(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
Copy link
Contributor

Choose a reason for hiding this comment

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

@themantissa will there be a update for this? since we don't have a forcenew on the requiered arguments (or any at all) any chance on this will force on a hard delete (remove then add the resource).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Eventually yes, but for now there is not. This is so tricky in how Terraform handles these! If someone does not realize what will happen if they, for example, change the name and, due to a ForceNew this removes and recreates the resource, it will delete all that person's data. If that's the only option that will make sense we need a very very clear warning in the docs that any change of the required parameters will result in a new serverless instance and data loss. fyi @shum the lack of a clean update on this is really painful for finding a solid way to protect users.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW names are immutable and will probably remain so

Copy link
Contributor

Choose a reason for hiding this comment

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

So let's leave it like this now, name might have to be force new and have a big fat warning in the docs, along other potential arguments. Since now it's in beta don't see an issue leaving it as is until it's implemented. Unless someone complains about the case I mentioned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 fyi @shum

@@ -1,7 +1,7 @@
---
layout: "mongodbatlas"
page_title: "MongoDB Atlas: search index"
sidebar_current: "docs-mongodbatlas-search-index"
sidebar_current: "docs-mongodbatlas-datasource-search-index"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this for another resource?

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! I realize that I made a previous mistake for this resource in other PR (the change is so little and don't have an impact in provider)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Any change that's not in the scope of the ticket should be another PR. This is okay this time but work should match the ticket.

@abner-dou abner-dou added run-testacc To run acceptance tests and removed run-testacc To run acceptance tests labels Oct 19, 2021
@abner-dou abner-dou added run-testacc To run acceptance tests and removed run-testacc To run acceptance tests labels Oct 19, 2021
Comment on lines 41 to 43
options := &matlas.ListOptions{}

serverlessInstances, _, err := conn.ServerlessInstances.List(ctx, projectID.(string), options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[q] why not nil?

Suggested change
options := &matlas.ListOptions{}
serverlessInstances, _, err := conn.ServerlessInstances.List(ctx, projectID.(string), options)
serverlessInstances, _, err := conn.ServerlessInstances.List(ctx, projectID.(string), nil)

also are we worry about users with more instances than the default pagination limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already managed the pagination with a recursive function to get all the instances

@abner-dou abner-dou added run-testacc To run acceptance tests and removed run-testacc To run acceptance tests labels Oct 25, 2021
@abner-dou abner-dou removed the run-testacc To run acceptance tests label Oct 26, 2021
@abner-dou abner-dou added the run-testacc To run acceptance tests label Oct 26, 2021
Copy link
Collaborator

@themantissa themantissa left a comment

Choose a reason for hiding this comment

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

Docs edits, thanks!

@@ -1,7 +1,7 @@
---
layout: "mongodbatlas"
page_title: "MongoDB Atlas: search index"
sidebar_current: "docs-mongodbatlas-search-index"
sidebar_current: "docs-mongodbatlas-datasource-search-index"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any change that's not in the scope of the ticket should be another PR. This is okay this time but work should match the ticket.

@themantissa
Copy link
Collaborator

themantissa commented Oct 27, 2021

@abner-dou is this ready for a re-review from Gustavo? If so please click the button to re-request. Though I'd fix the tests first.

@abner-dou abner-dou added run-testacc To run acceptance tests and removed run-testacc To run acceptance tests labels Oct 27, 2021
@abner-dou abner-dou requested a review from themantissa October 27, 2021 19:00
@abner-dou abner-dou added run-testacc To run acceptance tests and removed run-testacc To run acceptance tests labels Oct 27, 2021
Copy link
Collaborator

@themantissa themantissa left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@themantissa
Copy link
Collaborator

@abner-dou again, is this ready for a re-review from Gustavo? If so please click the button to re-request. I don't want to do it if it's not ready, i.e. his comments aren't addressed. @thetonymaster can you do the DoU review here?

@abner-dou abner-dou requested a review from gssbzn October 27, 2021 23:36
Copy link
Collaborator

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the pagination

Copy link
Contributor

@thetonymaster thetonymaster left a comment

Choose a reason for hiding this comment

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

LGTM

@abner-dou abner-dou merged commit 99bb60e into master Oct 28, 2021
@abner-dou abner-dou deleted the INTMDB-227-serverless branch October 28, 2021 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-testacc To run acceptance tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants