-
Notifications
You must be signed in to change notification settings - Fork 189
fix: Handles updates of mongodbatlas_global_cluster_config
#3060
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
if newEntry, exists := newMap[key]; exists { | ||
// Modification detected: key exists but value differs. | ||
if !reflect.DeepEqual(oldEntry, newEntry) { | ||
return diag.FromErr(fmt.Errorf("managed namespace for collection '%s' in db '%s' cannot be modified; remove it and add a new entry instead", oldEntry["collection"], oldEntry["db"])) |
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.
remove it and add a new entry is incorrect. They simply can't change it and we should ask upstream updates on how to handle this.
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 removed that part of the error message. But I want to clarify that it is possible, even if not recommended, to delete and create if user wants to
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.
Upstream confirmed that it's not recommended to drop and re-create to update, but possible if the user wants to do it. This is hard to avoid if we want to allow deleting and creating managed_namespaces. Which as far as I know we should allow
I have tested this from the TSE perspective and below are the results:
|
Co-authored-by: Marco Suma <[email protected]>
APIx bot: a message has been sent to Docs Slack channel |
@@ -0,0 +1,3 @@ | |||
```release-note:enhancement | |||
resource/mongodbatlas_global_cluster_config: Supports update operation |
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 think it would be easier to review if this was done in two PRs, one with the revert without any additional change, next PR with the changes, so we can spot better the real changes after the revert
internal/service/globalclusterconfig/resource_global_cluster_config_test.go
Show resolved
Hide resolved
internal/service/globalclusterconfig/resource_global_cluster_config.go
Outdated
Show resolved
Hide resolved
if isShardKeyUnique, okShard := mn["is_shard_key_unique"]; okShard { | ||
addManagedNamespace.IsShardKeyUnique = conversion.Pointer[bool](isShardKeyUnique.(bool)) | ||
} | ||
_, _, err := connV2.GlobalClustersApi.CreateManagedNamespace(ctx, projectID, clusterName, addManagedNamespace).Execute() |
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.
What happens in case this errors out for a particular namespace? Right now I think it would just fail right away and not complete the loop. Should we instead capture errors from all calls and fail once?
Same for deleting namespaces and adding custom zone mappings
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 think failing right away is okay, but I haven't thought about the alternative or if we should complete the loop in case of a single failure. No strong opinion from me on this
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'm okay failing right away. Only thing to consider is users might run follow-up updates in those cases, and as long as that works as expected and doesn't run into any state inconsistencies this should be fine.
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
internal/service/globalclusterconfig/resource_global_cluster_config.go
Outdated
Show resolved
Hide resolved
internal/service/globalclusterconfig/resource_global_cluster_config.go
Outdated
Show resolved
Hide resolved
internal/service/globalclusterconfig/resource_global_cluster_config.go
Outdated
Show resolved
Hide resolved
…onfig.go Co-authored-by: Leo Antoli <[email protected]>
Co-authored-by: John Williams <[email protected]>
* master: chore: Updates CHANGELOG.md for #3060 fix: Handles updates of `mongodbatlas_global_cluster_config` (#3060) chore: Updates CHANGELOG.md for #3069 fix: Handle the deleted on the backend case correctly for `mongodbatlas_database_user` resource (#3069) build(deps): bump go.mongodb.org/atlas-sdk (#3082)
* handle update * change error message * changelog * docs change * test changes * Update docs/resources/global_cluster_config.md Co-authored-by: Marco Suma <[email protected]> * reference API * add partial and total removal of custom_zone_mappings in test * refactor update * pr suggestions * Update internal/service/globalclusterconfig/resource_global_cluster_config.go Co-authored-by: Leo Antoli <[email protected]> * Update docs/resources/global_cluster_config.md Co-authored-by: John Williams <[email protected]> --------- Co-authored-by: Marco Suma <[email protected]> Co-authored-by: Leo Antoli <[email protected]> Co-authored-by: John Williams <[email protected]>
Description
Reverts #2282 to be able to handle updates of
mongodbatlas_global_cluster_config
but with the following adaptations:managed_namespace
entry is being modified. We can manage collection and db fields to do so.managed_namespace
entries call the POST for each of themmanaged_namespace
entries call the DELETE for each of themcustom_zone_mappings
and call the POST for each of themcustom_zone_mappings
deletion if all of them are being deletedLink to any related issue(s): CLOUDP-301529
Type of change:
Required Checklist:
Further comments