Skip to content

Commit

Permalink
chore: Refactors fail_index_key_too_long to be compatible with old im…
Browse files Browse the repository at this point in the history
…plementation and use zero values in advanced_configuration (#2893)

* chore: Refactor fail_index_key_too_long to be compatible with old implementation and use zero values in advanced_configuration

* chore: fix formatting

* fix: nil pointer error

* chore: Update failIndexKeyTooLong retrieval to use getter method
  • Loading branch information
EspenAlbert authored Dec 16, 2024
1 parent 47633ce commit 064955c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetFailIndexKeyTooLong()
if tfModel != nil {
stateConfig := tfModel.AdvancedConfiguration
stateConfigSDK := NewAtlasReqAdvancedConfigurationLegacy(ctx, &stateConfig, diags)
if diags.HasError() {
return
}
if stateConfigSDK != nil && stateConfigSDK.GetFailIndexKeyTooLong() != failIndexKeyTooLong {
failIndexKeyTooLong = stateConfigSDK.GetFailIndexKeyTooLong()
}
}
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(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)
Expand Down
9 changes: 3 additions & 6 deletions internal/service/advancedclustertpf/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,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,
PlanModifiers: []planmodifier.Bool{
PlanMustUseMongoDBVersion(4.4, EqualOrLower),
},
DeprecationMessage: DeprecationMsgOldSchema,
Computed: true,
Optional: true,
MarkdownDescription: "fail_index_key_too_long", // TODO: add description
},
},
Expand Down

0 comments on commit 064955c

Please sign in to comment.