From 19c703f4d377439326a1eaf81e0084a63ace3d51 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Fri, 10 Jan 2025 16:29:56 +0000 Subject: [PATCH] refactor: Reuses `advanced_cluster` logic in SDKv2 & TPF initial single file `common.go` (#2947) * refactor: Moves TestAccMockableAdvancedCluster_basicTenant to SDKv2 * test(unit): use IsTfLogDebug and support logging config in both REPLAY & CAPTURE * refactor: move TPF resource_tests to sdkv2 * refactor: move testdata for TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate.yaml * refactor: move testdata for TestAccMockableAdvancedCluster_shardedBasic.yaml * refactor: move testdata for TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml * chore: log also query string in request matching and add QueryVars to mockConfig * chore: Support testmact in makefile and use it in github action * feat: add timeouts attribute support in advanced cluster schema conversion * refactor: consolidate data source definitions in advanced cluster tests * feat: add support for HTTP mock capture in testmact-capture target * refactor: move testdata for TestAccMockableAdvancedCluster_tenantUpgrade.yaml * refactor: move testdata for TestAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml * test: ensure timeouts.create attribute is only checked on resource * fix: enforce explicit setting of ACCTEST_PACKAGES for testmact targets * chore: regenerate test files * chore: Add ORG_ID env var when using replay * fix: update minimum_enabled_tls_protocol to TLS1.2 and refactor timeout check in advanced cluster tests * test: Add more checks to new acceptance tests * fix: update advanced cluster test data sources to include new schema * chore: regen replicasetAdvConfigUpdate test * fix: update acceptance tests configuration to use correct package path and add regex for test selection * test: Refactor tests to use consistent TF config for data sources * fix: update advanced cluster test to correct timeout attribute and refactor update for TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate * refactor: remove test cases functions for new tests * chore: use new schema for testmact if it is not set * chore: regenerate mock data * refactor: Moves AddIDsToReplicationSpecs to TPF and reuse FormatMongoDBMajorVersion * refactor: Replace getAdvancedClusterContainerID with advancedclustertpf.GetAdvancedClusterContainerID for improved code reuse * refactor: Reuse advanced configuration handling in createCluster function * refactor: Update acceptance tests runner to include common.go in advanced cluster filters * refactor: rename test function and make update compatible with SDKv2 * refactor: remove redundant VERSION assignments in GNUmakefile [ci skip] * refactor: remove redundant VERSION assignment in GNUmakefile * apply PR suggestion --- .github/workflows/acceptance-tests-runner.yml | 1 + GNUmakefile | 4 - .../advancedcluster/model_advanced_cluster.go | 25 +--- .../advancedcluster/resource_update_logic.go | 20 +-- .../resource_update_logic_test.go | 116 ---------------- internal/service/advancedclustertpf/common.go | 46 +++++++ .../service/advancedclustertpf/common_test.go | 126 ++++++++++++++++++ .../service/advancedclustertpf/resource.go | 40 +----- .../resource_compatibility_reuse.go | 27 +--- 9 files changed, 187 insertions(+), 218 deletions(-) create mode 100644 internal/service/advancedclustertpf/common.go create mode 100644 internal/service/advancedclustertpf/common_test.go diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index 4cb2712a26..a4d191af96 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -244,6 +244,7 @@ jobs: filters: | advanced_cluster: - 'internal/service/advancedcluster/!(*_test).go' # matches any adv_cluster file change except test files + - 'internal/service/advancedclustertpf/common.go' advanced_cluster_tpf: - 'internal/service/advancedclustertpf/*.go' - 'internal/service/advancedcluster/*_test.go' diff --git a/GNUmakefile b/GNUmakefile index 07f0c11435..25def640db 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -42,7 +42,6 @@ test: fmtcheck .PHONY: testmact testmact: - @$(eval VERSION=macct) @$(eval ACCTEST_REGEX_RUN?=^TestAccMockable) @$(eval export HTTP_MOCKER_REPLAY?=true) @$(eval export HTTP_MOCKER_CAPTURE?=false) @@ -57,7 +56,6 @@ testmact: .PHONY: testmact-capture testmact-capture: - @$(eval VERSION=macct) @$(eval export ACCTEST_REGEX_RUN?=^TestAccMockable) @$(eval export HTTP_MOCKER_REPLAY?=false) @$(eval export HTTP_MOCKER_CAPTURE?=true) @@ -69,13 +67,11 @@ testmact-capture: .PHONY: testacc testacc: fmtcheck - @$(eval VERSION=acc) @$(eval ACCTEST_REGEX_RUN?=^TestAcc) TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)" .PHONY: testaccgov testaccgov: fmtcheck - @$(eval VERSION=acc) TF_ACC=1 go test ./... -run 'TestAccProjectRSGovProject_CreateWithProjectOwner' -v -parallel 1 "$(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags=$(LINKER_FLAGS) " .PHONY: fmt diff --git a/internal/service/advancedcluster/model_advanced_cluster.go b/internal/service/advancedcluster/model_advanced_cluster.go index bee87ae173..e2e8f01660 100644 --- a/internal/service/advancedcluster/model_advanced_cluster.go +++ b/internal/service/advancedcluster/model_advanced_cluster.go @@ -21,6 +21,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedclustertpf" ) const minVersionForChangeStreamOptions = 6.0 @@ -404,10 +405,7 @@ func ResourceClusterListAdvancedRefreshFunc(ctx context.Context, projectID strin } func FormatMongoDBMajorVersion(val any) string { - if strings.Contains(val.(string), ".") { - return val.(string) - } - return fmt.Sprintf("%.1f", cast.ToFloat32(val)) + return advancedclustertpf.FormatMongoDBMajorVersion(val.(string)) } func flattenLabels(l []admin.ComponentLabel) []map[string]string { @@ -711,7 +709,7 @@ func flattenAdvancedReplicationSpecRegionConfigs(ctx context.Context, apiObjects if err != nil { return nil, nil, err } - if result := getAdvancedClusterContainerID(containers.GetResults(), &apiObject); result != "" { + if result := advancedclustertpf.GetAdvancedClusterContainerID(containers.GetResults(), &apiObject); result != "" { // Will print as "providerName:regionName" = "containerId" in terraform show containerIDs[fmt.Sprintf("%s:%s", apiObject.GetProviderName(), apiObject.GetRegionName())] = result } @@ -845,23 +843,6 @@ func flattenAdvancedReplicationSpecAutoScaling(apiObject *admin.AdvancedAutoScal return tfList } -func getAdvancedClusterContainerID(containers []admin.CloudProviderContainer, cluster *admin.CloudRegionConfig20240805) string { - if len(containers) == 0 { - return "" - } - for i := range containers { - if cluster.GetProviderName() == constant.GCP { - return containers[i].GetId() - } - if containers[i].GetProviderName() == cluster.GetProviderName() && - containers[i].GetRegion() == cluster.GetRegionName() || // For Azure - containers[i].GetRegionName() == cluster.GetRegionName() { // For AWS - return containers[i].GetId() - } - } - return "" -} - func expandProcessArgs(d *schema.ResourceData, p map[string]any, mongodbMajorVersion *string) (admin20240530.ClusterDescriptionProcessArgs, admin.ClusterDescriptionProcessArgs20240805) { res20240530 := admin20240530.ClusterDescriptionProcessArgs{} res := admin.ClusterDescriptionProcessArgs20240805{} diff --git a/internal/service/advancedcluster/resource_update_logic.go b/internal/service/advancedcluster/resource_update_logic.go index 900cbb4570..76b1754084 100644 --- a/internal/service/advancedcluster/resource_update_logic.go +++ b/internal/service/advancedcluster/resource_update_logic.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedclustertpf" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -31,27 +32,10 @@ func populateIDValuesUsingNewAPI(ctx context.Context, projectID, clusterName str } zoneToReplicationSpecsIDs := groupIDsByZone(cluster.GetReplicationSpecs()) - result := AddIDsToReplicationSpecs(*replicationSpecs, zoneToReplicationSpecsIDs) + result := advancedclustertpf.AddIDsToReplicationSpecs(*replicationSpecs, zoneToReplicationSpecsIDs) return &result, nil } -func AddIDsToReplicationSpecs(replicationSpecs []admin.ReplicationSpec20240805, zoneToReplicationSpecsIDs map[string][]string) []admin.ReplicationSpec20240805 { - for zoneName, availableIDs := range zoneToReplicationSpecsIDs { - var indexOfIDToUse = 0 - for i := range replicationSpecs { - if indexOfIDToUse >= len(availableIDs) { - break // all available ids for this zone have been used - } - if replicationSpecs[i].GetZoneName() == zoneName { - newID := availableIDs[indexOfIDToUse] - indexOfIDToUse++ - replicationSpecs[i].Id = &newID - } - } - } - return replicationSpecs -} - func groupIDsByZone(specs []admin.ReplicationSpec20240805) map[string][]string { result := make(map[string][]string) for _, spec := range specs { diff --git a/internal/service/advancedcluster/resource_update_logic_test.go b/internal/service/advancedcluster/resource_update_logic_test.go index 9f476e9d08..f0336c86c8 100644 --- a/internal/service/advancedcluster/resource_update_logic_test.go +++ b/internal/service/advancedcluster/resource_update_logic_test.go @@ -8,122 +8,6 @@ import ( "go.mongodb.org/atlas-sdk/v20241113004/admin" ) -func TestAddIDsToReplicationSpecs(t *testing.T) { - testCases := map[string]struct { - ReplicationSpecs []admin.ReplicationSpec20240805 - ZoneToReplicationSpecsIDs map[string][]string - ExpectedReplicationSpecs []admin.ReplicationSpec20240805 - }{ - "two zones with same amount of available ids and replication specs to populate": { - ReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - }, - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - }, - }, - ZoneToReplicationSpecsIDs: map[string][]string{ - "Zone 1": {"zone1-id1", "zone1-id2"}, - "Zone 2": {"zone2-id1", "zone2-id2"}, - }, - ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - Id: admin.PtrString("zone1-id1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - Id: admin.PtrString("zone2-id1"), - }, - { - ZoneName: admin.PtrString("Zone 1"), - Id: admin.PtrString("zone1-id2"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - Id: admin.PtrString("zone2-id2"), - }, - }, - }, - "less available ids than replication specs to populate": { - ReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - }, - }, - ZoneToReplicationSpecsIDs: map[string][]string{ - "Zone 1": {"zone1-id1"}, - "Zone 2": {"zone2-id1"}, - }, - ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - Id: admin.PtrString("zone1-id1"), - }, - { - ZoneName: admin.PtrString("Zone 1"), - Id: nil, - }, - { - ZoneName: admin.PtrString("Zone 1"), - Id: nil, - }, - { - ZoneName: admin.PtrString("Zone 2"), - Id: admin.PtrString("zone2-id1"), - }, - }, - }, - "more available ids than replication specs to populate": { - ReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - }, - }, - ZoneToReplicationSpecsIDs: map[string][]string{ - "Zone 1": {"zone1-id1", "zone1-id2"}, - "Zone 2": {"zone2-id1", "zone2-id2"}, - }, - ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ - { - ZoneName: admin.PtrString("Zone 1"), - Id: admin.PtrString("zone1-id1"), - }, - { - ZoneName: admin.PtrString("Zone 2"), - Id: admin.PtrString("zone2-id1"), - }, - }, - }, - } - - for name, tc := range testCases { - t.Run(name, func(t *testing.T) { - resultSpecs := advancedcluster.AddIDsToReplicationSpecs(tc.ReplicationSpecs, tc.ZoneToReplicationSpecsIDs) - assert.Equal(t, tc.ExpectedReplicationSpecs, resultSpecs) - }) - } -} - func TestSyncAutoScalingConfigs(t *testing.T) { testCases := map[string]struct { ReplicationSpecs []admin.ReplicationSpec20240805 diff --git a/internal/service/advancedclustertpf/common.go b/internal/service/advancedclustertpf/common.go new file mode 100644 index 0000000000..35c0f8cd5e --- /dev/null +++ b/internal/service/advancedclustertpf/common.go @@ -0,0 +1,46 @@ +package advancedclustertpf + +import ( + "fmt" + "strings" + + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" + "github.com/spf13/cast" + "go.mongodb.org/atlas-sdk/v20241113004/admin" +) + +func FormatMongoDBMajorVersion(version string) string { + if strings.Contains(version, ".") { + return version + } + return fmt.Sprintf("%.1f", cast.ToFloat32(version)) +} + +func AddIDsToReplicationSpecs(replicationSpecs []admin.ReplicationSpec20240805, zoneToReplicationSpecsIDs map[string][]string) []admin.ReplicationSpec20240805 { + for zoneName, availableIDs := range zoneToReplicationSpecsIDs { + indexOfIDToUse := 0 + for i := range replicationSpecs { + if indexOfIDToUse >= len(availableIDs) { + break // all available ids for this zone have been used + } + if replicationSpecs[i].GetZoneName() == zoneName { + newID := availableIDs[indexOfIDToUse] + indexOfIDToUse++ + replicationSpecs[i].Id = &newID + } + } + } + return replicationSpecs +} + +func GetAdvancedClusterContainerID(containers []admin.CloudProviderContainer, cluster *admin.CloudRegionConfig20240805) string { + for i, container := range containers { + gpc := cluster.GetProviderName() == constant.GCP + azure := container.GetProviderName() == cluster.GetProviderName() && container.GetRegion() == cluster.GetRegionName() + aws := container.GetRegionName() == cluster.GetRegionName() + if gpc || azure || aws { + return containers[i].GetId() + } + } + return "" +} diff --git a/internal/service/advancedclustertpf/common_test.go b/internal/service/advancedclustertpf/common_test.go new file mode 100644 index 0000000000..bf8ae31683 --- /dev/null +++ b/internal/service/advancedclustertpf/common_test.go @@ -0,0 +1,126 @@ +package advancedclustertpf_test + +import ( + "testing" + + "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedclustertpf" + "github.com/stretchr/testify/assert" + + "go.mongodb.org/atlas-sdk/v20241113004/admin" +) + +func TestAddIDsToReplicationSpecs(t *testing.T) { + testCases := map[string]struct { + ReplicationSpecs []admin.ReplicationSpec20240805 + ZoneToReplicationSpecsIDs map[string][]string + ExpectedReplicationSpecs []admin.ReplicationSpec20240805 + }{ + "two zones with same amount of available ids and replication specs to populate": { + ReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + }, + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + }, + }, + ZoneToReplicationSpecsIDs: map[string][]string{ + "Zone 1": {"zone1-id1", "zone1-id2"}, + "Zone 2": {"zone2-id1", "zone2-id2"}, + }, + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + Id: admin.PtrString("zone1-id1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + Id: admin.PtrString("zone2-id1"), + }, + { + ZoneName: admin.PtrString("Zone 1"), + Id: admin.PtrString("zone1-id2"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + Id: admin.PtrString("zone2-id2"), + }, + }, + }, + "less available ids than replication specs to populate": { + ReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + }, + }, + ZoneToReplicationSpecsIDs: map[string][]string{ + "Zone 1": {"zone1-id1"}, + "Zone 2": {"zone2-id1"}, + }, + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + Id: admin.PtrString("zone1-id1"), + }, + { + ZoneName: admin.PtrString("Zone 1"), + Id: nil, + }, + { + ZoneName: admin.PtrString("Zone 1"), + Id: nil, + }, + { + ZoneName: admin.PtrString("Zone 2"), + Id: admin.PtrString("zone2-id1"), + }, + }, + }, + "more available ids than replication specs to populate": { + ReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + }, + }, + ZoneToReplicationSpecsIDs: map[string][]string{ + "Zone 1": {"zone1-id1", "zone1-id2"}, + "Zone 2": {"zone2-id1", "zone2-id2"}, + }, + ExpectedReplicationSpecs: []admin.ReplicationSpec20240805{ + { + ZoneName: admin.PtrString("Zone 1"), + Id: admin.PtrString("zone1-id1"), + }, + { + ZoneName: admin.PtrString("Zone 2"), + Id: admin.PtrString("zone2-id1"), + }, + }, + }, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + resultSpecs := advancedclustertpf.AddIDsToReplicationSpecs(tc.ReplicationSpecs, tc.ZoneToReplicationSpecsIDs) + assert.Equal(t, tc.ExpectedReplicationSpecs, resultSpecs) + }) + } +} diff --git a/internal/service/advancedclustertpf/resource.go b/internal/service/advancedclustertpf/resource.go index 448f8e56d6..b1d4565c2c 100644 --- a/internal/service/advancedclustertpf/resource.go +++ b/internal/service/advancedclustertpf/resource.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/update" @@ -46,10 +47,8 @@ const ( errorUnknownChangeReason = "unknown change reason" errorAwaitState = "error awaiting cluster to reach desired state" errorAwaitStateResultType = "the result of awaiting cluster wasn't of the expected type" - - // TODO: Used in two places - errorAdvancedConfUpdate = "error updating Advanced Configuration" - errorAdvancedConfUpdateLegacy = "error updating Advanced Configuration from legacy API" + errorAdvancedConfUpdate = "error updating Advanced Configuration" + errorAdvancedConfUpdateLegacy = "error updating Advanced Configuration from legacy API" DeprecationOldSchemaAction = "Please refer to our examples, documentation, and 1.18.0 migration guide for more details at https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/1.18.0-upgrade-guide.html.markdown" defaultTimeout = 3 * time.Hour @@ -230,7 +229,6 @@ func (r *rs) createCluster(ctx context.Context, plan *TFModel, diags *diag.Diagn projectID = plan.ProjectID.ValueString() clusterName = plan.Name.ValueString() api20240805 = r.Client.AtlasV220240805.ClustersApi - api20240530 = r.Client.AtlasV220240530.ClustersApi api = r.Client.AtlasV2.ClustersApi err error pauseAfter = latestReq.GetPaused() @@ -255,34 +253,10 @@ func (r *rs) createCluster(ctx context.Context, plan *TFModel, diags *diag.Diagn if pauseAfter { clusterResp = r.updateAndWait(ctx, &pauseRequest, diags, plan) } - var legacyAdvConfig *admin20240530.ClusterDescriptionProcessArgs - legacyAdvConfigUpdate := NewAtlasReqAdvancedConfigurationLegacy(ctx, &plan.AdvancedConfiguration, diags) - if !update.IsZeroValues(legacyAdvConfigUpdate) { - legacyAdvConfig, _, err = api20240530.UpdateClusterAdvancedConfiguration(ctx, projectID, clusterName, legacyAdvConfigUpdate).Execute() - if err != nil { - // Maybe should be warning instead of error to avoid having to re-create the cluster - diags.AddError(errorAdvancedConfUpdateLegacy, defaultAPIErrorDetails(clusterName, err)) - return nil - } - _ = AwaitChanges(ctx, r.Client.AtlasV2.ClustersApi, &plan.Timeouts, diags, projectID, clusterName, changeReasonCreate) - if diags.HasError() { - return nil - } - } - - advConfigUpdate := NewAtlasReqAdvancedConfiguration(ctx, &plan.AdvancedConfiguration, diags) - var advConfig *admin.ClusterDescriptionProcessArgs20240805 - if !update.IsZeroValues(advConfigUpdate) { - advConfig, _, err = api.UpdateClusterAdvancedConfiguration(ctx, projectID, clusterName, advConfigUpdate).Execute() - if err != nil { - // Maybe should be warning instead of error to avoid having to re-create the cluster - diags.AddError(errorAdvancedConfUpdate, defaultAPIErrorDetails(clusterName, err)) - return nil - } - _ = AwaitChanges(ctx, r.Client.AtlasV2.ClustersApi, &plan.Timeouts, diags, projectID, clusterName, changeReasonCreate) - if diags.HasError() { - return nil - } + emptyState := &TFModel{AdvancedConfiguration: types.ObjectNull(AdvancedConfigurationObjType.AttrTypes)} + legacyAdvConfig, advConfig, _ := r.applyAdvancedConfigurationChanges(ctx, diags, emptyState, plan) + if diags.HasError() { + return nil } modelOut, _ := getBasicClusterModel(ctx, diags, r.Client, clusterResp, plan, false) if diags.HasError() { diff --git a/internal/service/advancedclustertpf/resource_compatibility_reuse.go b/internal/service/advancedclustertpf/resource_compatibility_reuse.go index a419fc8929..46a7b87f62 100644 --- a/internal/service/advancedclustertpf/resource_compatibility_reuse.go +++ b/internal/service/advancedclustertpf/resource_compatibility_reuse.go @@ -4,12 +4,9 @@ import ( "context" "fmt" "strconv" - "strings" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" - "github.com/spf13/cast" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -47,13 +44,6 @@ func MajorVersionCompatible(input *string, version float64, operator MajorVersio return &result } -func FormatMongoDBMajorVersion(version string) string { - if strings.Contains(version, ".") { - return version - } - return fmt.Sprintf("%.1f", cast.ToFloat32(version)) -} - func containerIDKey(providerName, regionName string) string { return fmt.Sprintf("%s:%s", providerName, regionName) } @@ -87,7 +77,7 @@ func resolveContainerIDs(ctx context.Context, projectID string, cluster *admin.C } responseCache[providerName] = containersResponse } - if results := getAdvancedClusterContainerID(containersResponse.GetResults(), ®ionConfig); results != "" { + if results := GetAdvancedClusterContainerID(containersResponse.GetResults(), ®ionConfig); results != "" { containerIDs[key] = results } else { return nil, fmt.Errorf("container id not found for %s", key) @@ -97,19 +87,6 @@ func resolveContainerIDs(ctx context.Context, projectID string, cluster *admin.C return containerIDs, nil } -// copied from model_advanced_cluster.go -func getAdvancedClusterContainerID(containers []admin.CloudProviderContainer, cluster *admin.CloudRegionConfig20240805) string { - for i, container := range containers { - gpc := cluster.GetProviderName() == constant.GCP - azure := container.GetProviderName() == cluster.GetProviderName() && container.GetRegion() == cluster.GetRegionName() - aws := container.GetRegionName() == cluster.GetRegionName() - if gpc || azure || aws { - return containers[i].GetId() - } - } - return "" -} - func replicationSpecIDsFromOldAPI(clusterRespOld *admin20240530.AdvancedClusterDescription) map[string]string { specs := clusterRespOld.GetReplicationSpecs() zoneNameSpecIDs := make(map[string]string, len(specs)) @@ -185,7 +162,7 @@ func populateIDValuesUsingNewAPI(ctx context.Context, projectID, clusterName str } zoneToReplicationSpecsIDs := groupIDsByZone(cluster.GetReplicationSpecs()) - result := advancedcluster.AddIDsToReplicationSpecs(*replicationSpecs, zoneToReplicationSpecsIDs) + result := AddIDsToReplicationSpecs(*replicationSpecs, zoneToReplicationSpecsIDs) return &result, nil }