Skip to content

Commit

Permalink
overrideUsingLegacySchema
Browse files Browse the repository at this point in the history
  • Loading branch information
lantoli committed Dec 16, 2024
1 parent 5d80ddc commit 4650006
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions internal/service/advancedclustertpf/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func (d *ds) readCluster(ctx context.Context, diags *diag.Diagnostics, modelDS *
ProjectID: modelDS.ProjectID,
Name: modelDS.Name,
}
// TODO: pass !UseReplicationSpecPerShard to overrideUsingLegacySchema
modelOut, extraInfo := getBasicClusterModel(ctx, diags, d.Client, clusterResp, modelIn)
modelOut, extraInfo := getBasicClusterModel(ctx, diags, d.Client, clusterResp, modelIn, !useReplicationSpecPerShard)
if diags.HasError() {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ExtraAPIInfo struct {
ContainerIDs map[string]string
UsingLegacySchema bool
AsymmetricShardUnsupported bool
OverrideUsingLegacySchema bool
}

func NewTFModel(ctx context.Context, input *admin.ClusterDescription20240805, timeout timeouts.Value, diags *diag.Diagnostics, apiInfo ExtraAPIInfo) *TFModel {
Expand Down
3 changes: 1 addition & 2 deletions internal/service/advancedclustertpf/plural_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func (d *pluralDS) readClusters(ctx context.Context, diags *diag.Diagnostics, pl
ProjectID: pluralModel.ProjectID,
Name: types.StringValue(clusterResp.GetName()),
}
// TODO: pass !UseReplicationSpecPerShard to overrideUsingLegacySchema
modelOut, extraInfo := getBasicClusterModel(ctx, diags, d.Client, clusterResp, modelIn)
modelOut, extraInfo := getBasicClusterModel(ctx, diags, d.Client, clusterResp, modelIn, !useReplicationSpecPerShard)
if diags.HasError() {
return 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 @@ -131,7 +131,7 @@ func (r *rs) Update(ctx context.Context, req resource.UpdateRequest, resp *resou
}
modelOut := &state
if clusterResp != nil {
modelOut, _ = getBasicClusterModel(ctx, diags, r.Client, clusterResp, &plan)
modelOut, _ = getBasicClusterModel(ctx, diags, r.Client, clusterResp, &plan, false)
if diags.HasError() {
return
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func (r *rs) createCluster(ctx context.Context, plan *TFModel, diags *diag.Diagn
return nil
}
}
modelOut, _ := getBasicClusterModel(ctx, diags, r.Client, clusterResp, plan)
modelOut, _ := getBasicClusterModel(ctx, diags, r.Client, clusterResp, plan, false)
if diags.HasError() {
return nil
}
Expand All @@ -263,7 +263,7 @@ func (r *rs) readCluster(ctx context.Context, diags *diag.Diagnostics, modelIn *
diags.AddError("errorRead", fmt.Sprintf(errorRead, clusterName, err.Error()))
return nil
}
modelOut, _ := getBasicClusterModel(ctx, diags, r.Client, readResp, modelIn)
modelOut, _ := getBasicClusterModel(ctx, diags, r.Client, readResp, modelIn, false)
if diags.HasError() {
return nil
}
Expand Down Expand Up @@ -429,8 +429,8 @@ func (r *rs) applyTenantUpgrade(ctx context.Context, plan *TFModel, upgradeReque
return AwaitChanges(ctx, api, &plan.Timeouts, diags, projectID, clusterName, changeReasonUpdate)
}

func getBasicClusterModel(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, clusterResp *admin.ClusterDescription20240805, modelIn *TFModel) (*TFModel, *ExtraAPIInfo) {
apiInfo := resolveAPIInfo(ctx, modelIn, diags, clusterResp, client)
func getBasicClusterModel(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, clusterResp *admin.ClusterDescription20240805, modelIn *TFModel, overrideUsingLegacySchema bool) (*TFModel, *ExtraAPIInfo) {
apiInfo := resolveAPIInfo(ctx, diags, client, modelIn, clusterResp, overrideUsingLegacySchema)
if diags.HasError() {
return nil, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func findNumShardsUpdates(ctx context.Context, state, plan *TFModel, diags *diag
return planCounts
}

func resolveAPIInfo(ctx context.Context, plan *TFModel, diags *diag.Diagnostics, clusterLatest *admin.ClusterDescription20240805, client *config.MongoDBClient) *ExtraAPIInfo {
func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, plan *TFModel, clusterLatest *admin.ClusterDescription20240805, overrideUsingLegacySchema bool) *ExtraAPIInfo {
rootDiskSize := conversion.NilForUnknown(plan.DiskSizeGB, plan.DiskSizeGB.ValueFloat64Pointer())
projectID := plan.ProjectID.ValueString()
zoneNameSpecIDs, asymmetricShardUnsupported, err := getReplicationSpecIDsFromOldAPI(ctx, projectID, plan.Name.ValueString(), client.AtlasV220240530.ClustersApi)
Expand Down

0 comments on commit 4650006

Please sign in to comment.