Skip to content

chore: Updates mongodbatlas_advanced_cluster (SDKv2 & TPF) to consume selected processArgs fields from the createCluster/updateCluster APIs #3231

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 23 commits into from
Apr 10, 2025

Conversation

maastha
Copy link
Collaborator

@maastha maastha commented Mar 31, 2025

Description

This PR updates Atlas SDK v20240805 generated from api-bot-update-v20240805-backport-cluster branch (mongodb/atlas-sdk-go#576)

Link to any related issue(s): CLOUDP-296222

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. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • 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 have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@maastha maastha changed the title chore: init chore: Updates mongodbatlas_advanced_cluster (SDKv2) to consume selected processArgs fields from the createCluster/updateCluster Mar 31, 2025
@maastha maastha changed the title chore: Updates mongodbatlas_advanced_cluster (SDKv2) to consume selected processArgs fields from the createCluster/updateCluster chore: Updates mongodbatlas_advanced_cluster (SDKv2) to consume selected processArgs fields from the createCluster/updateCluster APIs Mar 31, 2025
@maastha maastha changed the title chore: Updates mongodbatlas_advanced_cluster (SDKv2) to consume selected processArgs fields from the createCluster/updateCluster APIs chore: Updates mongodbatlas_advanced_cluster (SDKv2 & TPF) to consume selected processArgs fields from the createCluster/updateCluster APIs Apr 2, 2025
@@ -348,7 +348,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.
return diag.FromErr(fmt.Errorf(ErrorAdvancedConfRead, "", clusterName, err))
}

if err := d.Set("advanced_configuration", flattenProcessArgs(processArgs20240530, processArgs)); err != nil {
if err := d.Set("advanced_configuration", flattenProcessArgs(processArgs20240530, processArgs, clusterDesc.AdvancedConfiguration)); err != nil {
Copy link
Collaborator Author

@maastha maastha Apr 2, 2025

Choose a reason for hiding this comment

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

although not an absolute requirement for Read, but still fetching these from cluster response (instead of /processArgs) for consistency.

@@ -939,7 +945,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.
}
waitOnUpdate = true
}
if d.HasChange("replica_set_scaling_strategy") || d.HasChange("redact_client_log_data") || d.HasChange("config_server_management_mode") {
if d.HasChange("replica_set_scaling_strategy") || d.HasChange("redact_client_log_data") || d.HasChange("config_server_management_mode") || d.HasChange("advanced_configuration") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@AgustinBettati can you confirm if this should be okay or we should update this in the above call (connV220240530.ClustersApi.UpdateCluster #L943)? In that case, will need the SDK for that to be updated as well to support the new AdvancedConfiguration attribute.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see a concern here, as we are still respecting what the comment below mentions when calling the latest API version.

can call latest API (2024-10-23 or newer) as replications specs (with nested autoscaling property) is not specified

In this case I understand we only add the advancedConfiguration property but no replicationSpecs, meaning no risk.

if diags.HasError() {
return
}
AddAdvancedConfig(ctx, modelOut, advConfig, legacyAdvConfig, diags)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updateModelAdvancedConfig already calls AddAdvancedConfig(), so this is not required

@maastha maastha marked this pull request as ready for review April 3, 2025 08:49
@maastha maastha requested a review from a team as a code owner April 3, 2025 08:49
NoTableScan: types.BoolValue(conversion.SafeValue(input.NoTableScan)),
OplogMinRetentionHours: types.Float64Value(conversion.SafeValue(input.OplogMinRetentionHours)),
OplogSizeMb: types.Int64Value(conversion.SafeValue(conversion.IntPtrToInt64Ptr(input.OplogSizeMB))),
SampleSizeBiconnector: types.Int64Value(conversion.SafeValue(conversion.IntPtrToInt64Ptr(input.SampleSizeBIConnector))),
SampleRefreshIntervalBiconnector: types.Int64Value(conversion.SafeValue(conversion.IntPtrToInt64Ptr(input.SampleRefreshIntervalBIConnector))),
TransactionLifetimeLimitSeconds: types.Int64Value(conversion.SafeValue(input.TransactionLifetimeLimitSeconds)),
DefaultMaxTimeMS: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(input.DefaultMaxTimeMS)),
TlsCipherConfigMode: types.StringValue(conversion.SafeValue(input.TlsCipherConfigMode)),
MinimumEnabledTlsProtocol: types.StringValue(conversion.SafeValue(clusterAdvConfig.MinimumEnabledTlsProtocol)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: you moved this from line 42 intentionally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

didn't remove anything, just moved MinimumEnabledTlsProtocol here

Copy link
Collaborator

Choose a reason for hiding this comment

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

yup, I said moved :) just wanted to check if you moved it intentionally and if there was a reason

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol I misread, yes moved intentionally just to keep these together for readability since they are both fetched from clusterAdvConfig

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.

from a first look, change LGTM - are you running all cluster tests? I remember we disabled some from regular PR execution.

@maastha
Copy link
Collaborator Author

maastha commented Apr 3, 2025

from a first look, change LGTM - are you running all cluster tests? I remember we disabled some from regular PR execution.

Yes I'm running them separately for this branch, will add links soon

p := aclist[0].(map[string]any)

if _, ok := d.GetOkExists("advanced_configuration.0.minimum_enabled_tls_protocol"); ok {
res.MinimumEnabledTlsProtocol = conversion.StringPtr(cast.ToString(p["minimum_enabled_tls_protocol"]))
Copy link
Collaborator

@oarbusi oarbusi Apr 3, 2025

Choose a reason for hiding this comment

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

nit: cast p["minimum_enabled_tls_protocol"].(string) instead of using the current way

@@ -1148,6 +1150,11 @@ func updateRequest(ctx context.Context, d *schema.ResourceData, projectID, clust
if d.HasChange("config_server_management_mode") {
cluster.ConfigServerManagementMode = conversion.StringPtr(d.Get("config_server_management_mode").(string))
}
if d.HasChange("advanced_configuration") {
if aclist, ok := d.Get("advanced_configuration").([]any); ok && len(aclist) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means that removing advanced_configuration from the config will never update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's the behavior today as well right? since it's O/C, or did you mean something else?

Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

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

Changes LGMT overall :)

@maastha
Copy link
Collaborator Author

maastha commented Apr 3, 2025

@@ -100,6 +100,11 @@ func UpdateAdvancedConfiguration(ctx context.Context, diags *diag.Diagnostics, c
return nil, nil, false
}
}
// clusterAdvConfig is managed through create/updateCluster APIs instead of processArgs APIs but since corresponding TF attributes
Copy link
Member

Choose a reason for hiding this comment

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

I think it can be confusing that UpdateAdvancedConfiguration doesn't update clusterAdvConfig, can we move this comment to be in the func description? although not ideal but I think it's clearer

Copy link
Member

Choose a reason for hiding this comment

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

also func is having many params, consider using a request struct

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved comment & updated to use struct, ty!

if clusterAdvConfig != nil {
flattenedProcessArgs[0]["tls_cipher_config_mode"] = clusterAdvConfig.GetTlsCipherConfigMode()
flattenedProcessArgs[0]["custom_openssl_cipher_config_tls12"] = clusterAdvConfig.GetCustomOpensslCipherConfigTls12()
flattenedProcessArgs[0]["minimum_enabled_tls_protocol"] = clusterAdvConfig.GetMinimumEnabledTlsProtocol()
Copy link
Member

Choose a reason for hiding this comment

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

can it happen that minimum_enabled_tls_protocol exists in p20240530 but not in clusterAdvConfig? in case it makes sense to keep reading it from p20240530, and override if present at clusterAdvConfig

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

var advancedConfig TFAdvancedConfigurationModel
if input != nil && inputLegacy != nil {
if input != nil && inputLegacy != nil && clusterAdvConfig != nil {
Copy link
Member

Choose a reason for hiding this comment

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

can it happen that clusterAdvConfig is nil and we want at least to see the other params that don't depend on it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, recently discovered for TENANT cluster type this may be the case, updated.

@@ -33,7 +33,7 @@ require (
github.com/zclconf/go-cty v1.16.2
go.mongodb.org/atlas v0.37.0
go.mongodb.org/atlas-sdk/v20240530005 v20240530005.0.0
go.mongodb.org/atlas-sdk/v20240805005 v20240805005.0.0
go.mongodb.org/atlas-sdk/v20240805005 v20240805005.0.1-0.20250402112219-2468c5354718 // uses api-bot-update-v20240805-backport-cluster to support AdvancedConfiguration in create/updateCluster APIs
Copy link
Member

Choose a reason for hiding this comment

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

I think there are no tests changes, can we add or modify tests to check these new attributes are set correctly? for instance in some tests first steps to check in the data source the attribute values

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

existing tests do check all these values to be set as expected

func checkAdvanced(usePreviewProvider bool, name, tls string, processArgs *admin.ClusterDescriptionProcessArgs20240805) resource.TestCheckFunc {

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

Comment on lines 105 to 107
if !update.IsZeroValues(clusterAdvConfig) {
changed = true
}
Copy link
Member

Choose a reason for hiding this comment

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

q: If clusterAdvConfig made some changes, is there a need to flag the changed here? If changes are made only in clusterAdvConfig I would expect once cluster is IDLE there is not need to detect changes here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed is required to be flagged here so that the advanced_configuration in the TF model is updated (which is required to be done if any of the params change)

@maastha
Copy link
Collaborator Author

maastha commented Apr 8, 2025

Will re-run complete acc test group advanced_cluster & TPF in sometime before merge as dev is unstable right now when creating new projects

Copy link
Member

@lantoli lantoli 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 follow-ups

@@ -20,6 +23,12 @@ var (
ErrLegacyIgnoreLabel = fmt.Errorf("label `%s` is not supported as it is reserved for internal purposes", LegacyIgnoredLabelKey)
)

type ProcessArgs struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice refactoring

Copy link
Collaborator

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Great job!

… fields from the createCluster/updateCluster APIs (#3250)
@maastha
Copy link
Collaborator Author

maastha commented Apr 10, 2025

only 1 cluster test failing due to OUT_OF_CAPACITY, merging

@maastha maastha merged commit 96d18c0 into master Apr 10, 2025
37 of 40 checks passed
@maastha maastha deleted the CLOUDP-296222-adv_conf_cluster_api branch April 10, 2025 12:43
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.

6 participants