Skip to content
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

chore: Refactors fail_index_key_too_long to be compatible with old implementation and use zero values in advanced_configuration #2893

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Comment on lines +30 to +32
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 FailIndexKeyTooLong is not defined in API response because an old mongodb version is used, wouldnt we want the user to be aware that this property was not set? How does this scenario work in SDK v2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In SDK v2 we use the Getter methods:
"fail_index_key_too_long": p20240530.GetFailIndexKeyTooLong(),
So even when the API returns null it will still be set to false

}
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
Loading