-
Notifications
You must be signed in to change notification settings - Fork 190
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
Conversation
@abner-dou not sure what happened here with the tests? |
@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 |
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
options := &matlas.ListOptions{ | ||
/* PageNum: d.Get("page_num").(int), | ||
ItemsPerPage: d.Get("items_per_page").(int), | ||
|
||
*/ | ||
} |
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.
[q] I am not sure why these lines are commented out
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.
I forgot to delete it
projectID, projectIDOK := d.GetOk("project_id") | ||
|
||
if !(projectIDOK) { | ||
return diag.Errorf("project_id must be configured") | ||
} |
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.
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") | |
} |
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.
I was just following the naming convention used in the provider for this cases, but I can change it this way
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.
I guess projectIDOK
it's fine since it's a boolean, and not an error
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.
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
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.
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 |
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.
You can rewrite this as len(serverlessInstances) > 0
and return nil, nil
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.
this condition is already in line 65
if len(serverlessInstances) == 0 {
return nil, nil
}
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, 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
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.
Also why are we returning an error where is none?
mongodbatlas/provider.go
Outdated
} | ||
|
||
if enableBetaFeatures := os.Getenv("MONGODB_ATLAS_ENABLE_BETA"); enableBetaFeatures == "true" { | ||
resourcesMap["mongodbatlas_serverless_instance"] = resourceMongoDBAtlasServerlessInstance() |
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.
can we add a function to add all beta features?
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.
a new function to set only beta features already added
mongodbatlas/provider.go
Outdated
"mongodbatlas_cloud_backup_schedule": resourceMongoDBAtlasCloudBackupSchedule(), | ||
}, | ||
if enableBetaFeatures := os.Getenv("MONGODB_ATLAS_ENABLE_BETA"); enableBetaFeatures == "true" { | ||
dataSourcesMap["mongodbatlas_serverless_instance"] = dataSourceMongoDBAtlasServerlessInstance() |
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.
same here, maybe we can just add a single function to add both, and receives dataSourcesMap
and resourcesMap
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.
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 { |
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.
@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).
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.
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.
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.
FWIW names are immutable and will probably remain so
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.
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.
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.
👍 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" |
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.
is this for another resource?
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! 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)
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.
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.
options := &matlas.ListOptions{} | ||
|
||
serverlessInstances, _, err := conn.ServerlessInstances.List(ctx, projectID.(string), options) |
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.
[q] why not nil?
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?
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.
I already managed the pagination with a recursive function to get all the instances
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.
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" |
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.
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 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. |
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, thank you!
@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? |
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 thanks for the pagination
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
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:
Required Checklist:
Further comments