From d39cf2f073eec031e73dc8f9b124673b5aca6855 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:43:34 +0100 Subject: [PATCH] address feedback --- .../service/advancedclustertpf/resource.go | 4 ++-- .../resource_compatiblity.go | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/service/advancedclustertpf/resource.go b/internal/service/advancedclustertpf/resource.go index cf9e0d458b..aae6fcab36 100644 --- a/internal/service/advancedclustertpf/resource.go +++ b/internal/service/advancedclustertpf/resource.go @@ -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, overrideUsingLegacySchema bool) (*TFModel, *ExtraAPIInfo) { - apiInfo := resolveAPIInfo(ctx, diags, client, modelIn, clusterResp, overrideUsingLegacySchema) +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) if diags.HasError() { return nil, nil } diff --git a/internal/service/advancedclustertpf/resource_compatiblity.go b/internal/service/advancedclustertpf/resource_compatiblity.go index 0b8bcea732..02f2e2a3f6 100644 --- a/internal/service/advancedclustertpf/resource_compatiblity.go +++ b/internal/service/advancedclustertpf/resource_compatiblity.go @@ -39,13 +39,14 @@ func findNumShardsUpdates(ctx context.Context, state, plan *TFModel, diags *diag return planCounts } -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() - clusterName := plan.Name.ValueString() - asymmetricShardUnsupported := false - - api20240530 := client.AtlasV220240530.ClustersApi +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 + ) clusterRespOld, _, err := api20240530.GetCluster(ctx, projectID, clusterName).Execute() if err != nil { if admin20240530.IsErrorCode(err, "ASYMMETRIC_SHARD_UNSUPPORTED") { @@ -69,9 +70,9 @@ func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config ZoneNameReplicationSpecIDs: replicationSpecIDsFromOldAPI(clusterRespOld), AsymmetricShardUnsupported: asymmetricShardUnsupported, } - if overrideUsingLegacySchema { + if forceLegacySchema { info.UsingLegacySchema = true - info.ZoneNameNumShards = numShardsMapFromOldAPI(clusterRespOld) + info.ZoneNameNumShards = numShardsMapFromOldAPI(clusterRespOld) // plan is empty in data source Read when forcing legacy, so we get num_shards from the old API } else { info.UsingLegacySchema = usingLegacySchema(ctx, plan.ReplicationSpecs, diags) info.ZoneNameNumShards = numShardsMap(ctx, plan.ReplicationSpecs, diags)