From 80b9b9c48706f412ed329c5d8575e20cdaddce27 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Sat, 14 Dec 2024 08:45:54 +0000 Subject: [PATCH 1/4] chore: Refactor fail_index_key_too_long to be compatible with old implementation and use zero values in advanced_configuration --- ...l_ClusterDescriptionProcessArgs20240805.go | 34 +++++++++++++------ .../advancedclustertpf/resource_schema.go | 3 -- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go index dbcd79b6b1..882a2ec0c8 100644 --- a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go +++ b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go @@ -19,19 +19,31 @@ func AddAdvancedConfig(ctx context.Context, tfModel *TFModel, input *admin.Clust // special behavior using -1 when it is unset by the user changeStreamOptionsPreAndPostImagesExpireAfterSeconds = conversion.Pointer(-1) } + // When MongoDBMajorVersion is not 4.4 or lower, the API response for fail_index_key_too_long will always be null, to ensure no consistency issues, we need to match the config + failIndexKeyTooLong := inputLegacy.FailIndexKeyTooLong + if tfModel != nil { + stateConfig := tfModel.AdvancedConfiguration + stateConfigSDK := NewAtlasReqAdvancedConfigurationLegacy(ctx, &stateConfig, diags) + if diags.HasError() { + return + } + if conversion.SafeValue(stateConfigSDK.FailIndexKeyTooLong) != conversion.SafeValue(failIndexKeyTooLong) { + failIndexKeyTooLong = stateConfigSDK.FailIndexKeyTooLong + } + } advancedConfig = TFAdvancedConfigurationModel{ ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(changeStreamOptionsPreAndPostImagesExpireAfterSeconds)), - DefaultWriteConcern: types.StringPointerValue(input.DefaultWriteConcern), - DefaultReadConcern: types.StringPointerValue(inputLegacy.DefaultReadConcern), - FailIndexKeyTooLong: types.BoolPointerValue(inputLegacy.FailIndexKeyTooLong), - JavascriptEnabled: types.BoolPointerValue(input.JavascriptEnabled), - MinimumEnabledTlsProtocol: types.StringPointerValue(input.MinimumEnabledTlsProtocol), - NoTableScan: types.BoolPointerValue(input.NoTableScan), - OplogMinRetentionHours: types.Float64PointerValue(input.OplogMinRetentionHours), - OplogSizeMb: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(input.OplogSizeMB)), - SampleSizeBiconnector: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(input.SampleSizeBIConnector)), - SampleRefreshIntervalBiconnector: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(input.SampleRefreshIntervalBIConnector)), - TransactionLifetimeLimitSeconds: types.Int64PointerValue(input.TransactionLifetimeLimitSeconds), + DefaultWriteConcern: types.StringValue(conversion.SafeValue(input.DefaultWriteConcern)), + DefaultReadConcern: types.StringValue(conversion.SafeValue(inputLegacy.DefaultReadConcern)), + FailIndexKeyTooLong: types.BoolValue(conversion.SafeValue(failIndexKeyTooLong)), + JavascriptEnabled: types.BoolValue(conversion.SafeValue(input.JavascriptEnabled)), + MinimumEnabledTlsProtocol: types.StringValue(conversion.SafeValue(input.MinimumEnabledTlsProtocol)), + 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)), } } objType, diagsLocal := types.ObjectValueFrom(ctx, AdvancedConfigurationObjType.AttrTypes, advancedConfig) diff --git a/internal/service/advancedclustertpf/resource_schema.go b/internal/service/advancedclustertpf/resource_schema.go index 001745c89a..92d63fb42d 100644 --- a/internal/service/advancedclustertpf/resource_schema.go +++ b/internal/service/advancedclustertpf/resource_schema.go @@ -494,9 +494,6 @@ func AdvancedConfigurationSchema(ctx context.Context) schema.SingleNestedAttribu DeprecationMessage: DeprecationMsgOldSchema, Computed: true, Optional: true, - PlanModifiers: []planmodifier.Bool{ - PlanMustUseMongoDBVersion(4.4, EqualOrLower), - }, MarkdownDescription: "fail_index_key_too_long", // TODO: add description }, }, From 519d2ee3f868e50835b43e51fbec1defb60311ab Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Sat, 14 Dec 2024 09:27:32 +0000 Subject: [PATCH 2/4] chore: fix formatting --- internal/service/advancedclustertpf/resource_schema.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/advancedclustertpf/resource_schema.go b/internal/service/advancedclustertpf/resource_schema.go index 92d63fb42d..679c42e674 100644 --- a/internal/service/advancedclustertpf/resource_schema.go +++ b/internal/service/advancedclustertpf/resource_schema.go @@ -491,9 +491,9 @@ func AdvancedConfigurationSchema(ctx context.Context) schema.SingleNestedAttribu MarkdownDescription: "default_read_concern", // TODO: add description }, "fail_index_key_too_long": schema.BoolAttribute{ - DeprecationMessage: DeprecationMsgOldSchema, - Computed: true, - Optional: true, + DeprecationMessage: DeprecationMsgOldSchema, + Computed: true, + Optional: true, MarkdownDescription: "fail_index_key_too_long", // TODO: add description }, }, From 93e986b4a94525ff7658c725649f47b3b708ad79 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Sat, 14 Dec 2024 11:21:34 +0000 Subject: [PATCH 3/4] fix: nil pointer error --- .../model_ClusterDescriptionProcessArgs20240805.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go index 882a2ec0c8..c1aa2f9878 100644 --- a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go +++ b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go @@ -27,7 +27,7 @@ func AddAdvancedConfig(ctx context.Context, tfModel *TFModel, input *admin.Clust if diags.HasError() { return } - if conversion.SafeValue(stateConfigSDK.FailIndexKeyTooLong) != conversion.SafeValue(failIndexKeyTooLong) { + if stateConfigSDK != nil && conversion.SafeValue(stateConfigSDK.FailIndexKeyTooLong) != conversion.SafeValue(failIndexKeyTooLong) { failIndexKeyTooLong = stateConfigSDK.FailIndexKeyTooLong } } From 9cad98866cfc8898b078e6b3ee527e458cefcef0 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Mon, 16 Dec 2024 08:05:24 +0000 Subject: [PATCH 4/4] chore: Update failIndexKeyTooLong retrieval to use getter method --- .../model_ClusterDescriptionProcessArgs20240805.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go index c1aa2f9878..ff14a68650 100644 --- a/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go +++ b/internal/service/advancedclustertpf/model_ClusterDescriptionProcessArgs20240805.go @@ -20,22 +20,22 @@ func AddAdvancedConfig(ctx context.Context, tfModel *TFModel, input *admin.Clust changeStreamOptionsPreAndPostImagesExpireAfterSeconds = conversion.Pointer(-1) } // When MongoDBMajorVersion is not 4.4 or lower, the API response for fail_index_key_too_long will always be null, to ensure no consistency issues, we need to match the config - failIndexKeyTooLong := inputLegacy.FailIndexKeyTooLong + failIndexKeyTooLong := inputLegacy.GetFailIndexKeyTooLong() if tfModel != nil { stateConfig := tfModel.AdvancedConfiguration stateConfigSDK := NewAtlasReqAdvancedConfigurationLegacy(ctx, &stateConfig, diags) if diags.HasError() { return } - if stateConfigSDK != nil && conversion.SafeValue(stateConfigSDK.FailIndexKeyTooLong) != conversion.SafeValue(failIndexKeyTooLong) { - failIndexKeyTooLong = stateConfigSDK.FailIndexKeyTooLong + if stateConfigSDK != nil && stateConfigSDK.GetFailIndexKeyTooLong() != failIndexKeyTooLong { + failIndexKeyTooLong = stateConfigSDK.GetFailIndexKeyTooLong() } } advancedConfig = TFAdvancedConfigurationModel{ ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(changeStreamOptionsPreAndPostImagesExpireAfterSeconds)), DefaultWriteConcern: types.StringValue(conversion.SafeValue(input.DefaultWriteConcern)), DefaultReadConcern: types.StringValue(conversion.SafeValue(inputLegacy.DefaultReadConcern)), - FailIndexKeyTooLong: types.BoolValue(conversion.SafeValue(failIndexKeyTooLong)), + FailIndexKeyTooLong: types.BoolValue(failIndexKeyTooLong), JavascriptEnabled: types.BoolValue(conversion.SafeValue(input.JavascriptEnabled)), MinimumEnabledTlsProtocol: types.StringValue(conversion.SafeValue(input.MinimumEnabledTlsProtocol)), NoTableScan: types.BoolValue(conversion.SafeValue(input.NoTableScan)),