Skip to content

Commit

Permalink
ForceLegacySchemaFailed (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli authored Dec 18, 2024
1 parent 9cdf77c commit 06140c9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion internal/service/advancedclustertpf/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (d *ds) readCluster(ctx context.Context, diags *diag.Diagnostics, modelDS *
if diags.HasError() {
return nil
}
if extraInfo.AsymmetricShardUnsupported && !useReplicationSpecPerShard {
if extraInfo.ForceLegacySchemaFailed {
diags.AddError("errorRead", "Please add `use_replication_spec_per_shard = true` to your data source configuration to enable asymmetric shard support. Refer to documentation for more details.")
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ExtraAPIInfo struct {
RootDiskSize *float64
ContainerIDs map[string]string
UsingLegacySchema bool
AsymmetricShardUnsupported bool
ForceLegacySchemaFailed bool
}

func NewTFModel(ctx context.Context, input *admin.ClusterDescription20240805, timeout timeouts.Value, diags *diag.Diagnostics, apiInfo ExtraAPIInfo) *TFModel {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/advancedclustertpf/plural_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (d *pluralDS) readClusters(ctx context.Context, diags *diag.Diagnostics, pl
if diags.HasError() {
return nil
}
if extraInfo.AsymmetricShardUnsupported && !useReplicationSpecPerShard {
if extraInfo.ForceLegacySchemaFailed {
continue
}
updateModelAdvancedConfig(ctx, diags, d.Client, modelOut, nil, nil)
Expand Down
10 changes: 5 additions & 5 deletions internal/service/advancedclustertpf/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,19 +453,19 @@ func (r *rs) applyTenantUpgrade(ctx context.Context, plan *TFModel, upgradeReque
}

func getBasicClusterModel(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, clusterResp *admin.ClusterDescription20240805, modelIn *TFModel, forceLegacySchema bool) (*TFModel, *ExtraAPIInfo) {
apiInfo := resolveAPIInfo(ctx, diags, client, modelIn, clusterResp, forceLegacySchema)
extraInfo := resolveAPIInfo(ctx, diags, client, modelIn, clusterResp, forceLegacySchema)
if diags.HasError() {
return nil, nil
}
if forceLegacySchema && apiInfo.AsymmetricShardUnsupported { // can't create a model if legacy is forced but cluster does not support it
return nil, apiInfo
if extraInfo.ForceLegacySchemaFailed { // can't create a model if legacy is forced but cluster does not support it
return nil, extraInfo
}
modelOut := NewTFModel(ctx, clusterResp, modelIn.Timeouts, diags, *apiInfo)
modelOut := NewTFModel(ctx, clusterResp, modelIn.Timeouts, diags, *extraInfo)
if diags.HasError() {
return nil, nil
}
overrideAttributesWithPrevStateValue(modelIn, modelOut)
return modelOut, apiInfo
return modelOut, extraInfo
}

func updateModelAdvancedConfig(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, model *TFModel, legacyAdvConfig *admin20240530.ClusterDescriptionProcessArgs, advConfig *admin.ClusterDescriptionProcessArgs20240805) {
Expand Down
14 changes: 7 additions & 7 deletions internal/service/advancedclustertpf/resource_compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ func findNumShardsUpdates(ctx context.Context, state, plan *TFModel, diags *diag

func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, plan *TFModel, clusterLatest *admin.ClusterDescription20240805, forceLegacySchema bool) *ExtraAPIInfo {
var (
api20240530 = client.AtlasV220240530.ClustersApi
rootDiskSize = conversion.NilForUnknown(plan.DiskSizeGB, plan.DiskSizeGB.ValueFloat64Pointer())
projectID = plan.ProjectID.ValueString()
clusterName = plan.Name.ValueString()
asymmetricShardUnsupported = false
api20240530 = client.AtlasV220240530.ClustersApi
rootDiskSize = conversion.NilForUnknown(plan.DiskSizeGB, plan.DiskSizeGB.ValueFloat64Pointer())
projectID = plan.ProjectID.ValueString()
clusterName = plan.Name.ValueString()
forceLegacySchemaFailed = false
)
clusterRespOld, _, err := api20240530.GetCluster(ctx, projectID, clusterName).Execute()
if err != nil {
if admin20240530.IsErrorCode(err, "ASYMMETRIC_SHARD_UNSUPPORTED") {
asymmetricShardUnsupported = true
forceLegacySchemaFailed = forceLegacySchema
} else {
diags.AddError("errorRead", fmt.Sprintf("error reading advanced cluster with 2024-05-30 API (%s): %s", clusterName, err))
return nil
Expand All @@ -68,7 +68,7 @@ func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config
ContainerIDs: containerIDs,
RootDiskSize: rootDiskSize,
ZoneNameReplicationSpecIDs: replicationSpecIDsFromOldAPI(clusterRespOld),
AsymmetricShardUnsupported: asymmetricShardUnsupported,
ForceLegacySchemaFailed: forceLegacySchemaFailed,
}
if forceLegacySchema {
info.UsingLegacySchema = true
Expand Down

0 comments on commit 06140c9

Please sign in to comment.