From 4650006d4557e84a99c15cbd3312ce9e9e83880e Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:29:40 +0100 Subject: [PATCH] overrideUsingLegacySchema --- internal/service/advancedclustertpf/data_source.go | 3 +-- .../model_ClusterDescription20240805.go | 1 + .../service/advancedclustertpf/plural_data_source.go | 3 +-- internal/service/advancedclustertpf/resource.go | 10 +++++----- .../advancedclustertpf/resource_compatiblity.go | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/service/advancedclustertpf/data_source.go b/internal/service/advancedclustertpf/data_source.go index b95aff557c..d3afe998ab 100644 --- a/internal/service/advancedclustertpf/data_source.go +++ b/internal/service/advancedclustertpf/data_source.go @@ -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 } diff --git a/internal/service/advancedclustertpf/model_ClusterDescription20240805.go b/internal/service/advancedclustertpf/model_ClusterDescription20240805.go index f77a7dfbc5..58a2a9d369 100644 --- a/internal/service/advancedclustertpf/model_ClusterDescription20240805.go +++ b/internal/service/advancedclustertpf/model_ClusterDescription20240805.go @@ -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 { diff --git a/internal/service/advancedclustertpf/plural_data_source.go b/internal/service/advancedclustertpf/plural_data_source.go index 6c8178345c..f9c83bbcbe 100644 --- a/internal/service/advancedclustertpf/plural_data_source.go +++ b/internal/service/advancedclustertpf/plural_data_source.go @@ -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 } diff --git a/internal/service/advancedclustertpf/resource.go b/internal/service/advancedclustertpf/resource.go index 265705ab90..cf9e0d458b 100644 --- a/internal/service/advancedclustertpf/resource.go +++ b/internal/service/advancedclustertpf/resource.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/internal/service/advancedclustertpf/resource_compatiblity.go b/internal/service/advancedclustertpf/resource_compatiblity.go index 85130bb473..e320c37c6c 100644 --- a/internal/service/advancedclustertpf/resource_compatiblity.go +++ b/internal/service/advancedclustertpf/resource_compatiblity.go @@ -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)