From 4d35c2c02d84635f2fb0e27a536032ef43b00ba9 Mon Sep 17 00:00:00 2001
From: Espen Albert <espen.albert@mongodb.com>
Date: Sat, 14 Dec 2024 08:51:43 +0000
Subject: [PATCH 1/2] chore: Add support for legacy cluster creation API in
 createCluster function

---
 internal/service/advancedclustertpf/resource.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/internal/service/advancedclustertpf/resource.go b/internal/service/advancedclustertpf/resource.go
index 3e92d1af58..3874df57cc 100644
--- a/internal/service/advancedclustertpf/resource.go
+++ b/internal/service/advancedclustertpf/resource.go
@@ -182,6 +182,7 @@ func (r *rs) createCluster(ctx context.Context, plan *TFModel, diags *diag.Diagn
 	var (
 		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
@@ -190,7 +191,12 @@ func (r *rs) createCluster(ctx context.Context, plan *TFModel, diags *diag.Diagn
 	if pauseAfter {
 		latestReq.Paused = nil
 	}
-	_, _, err = api.CreateCluster(ctx, projectID, latestReq).Execute()
+	if usingLegacySchema(ctx, plan.ReplicationSpecs, diags) {
+		legacyReq := newLegacyModel(latestReq)
+		_, _, err = api20240805.CreateCluster(ctx, projectID, legacyReq).Execute()
+	} else {
+		_, _, err = api.CreateCluster(ctx, projectID, latestReq).Execute()
+	}
 	if err != nil {
 		diags.AddError("errorCreate", fmt.Sprintf(errorCreate, err.Error()))
 		return nil

From 5b02114bbb719d09970c1bfca56669261d410953 Mon Sep 17 00:00:00 2001
From: Espen Albert <espen.albert@mongodb.com>
Date: Sat, 14 Dec 2024 08:55:49 +0000
Subject: [PATCH 2/2] chore: Update create in legacy test to use the 08-05 API
 version

---
 ...tAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml | 4 ++--
 ...T__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json} | 0
 ...r_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml | 4 ++--
 ...T__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json} | 0
 4 files changed, 4 insertions(+), 4 deletions(-)
 rename internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema/{01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json => 01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json} (100%)
 rename internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel/{01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json => 01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json} (100%)

diff --git a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml
index b5944cdc17..589d709dde 100644
--- a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml
+++ b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema.yaml
@@ -5,7 +5,7 @@ steps:
   - diff_requests:
       - path: /api/atlas/v2/groups/{groupId}/clusters
         method: POST
-        version: '2024-10-23'
+        version: '2024-08-05'
         text: "{\n \"clusterType\": \"SHARDED\",\n \"configServerManagementMode\": \"FIXED_TO_DEDICATED\",\n \"labels\": [],\n \"mongoDBMajorVersion\": \"8.0\",\n \"name\": \"{clusterName}\",\n \"replicationSpecs\": [\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 1\n     },\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"EU_WEST_1\"\n    },\n    {\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 2\n     },\n     \"priority\": 6,\n     \"providerName\": \"AZURE\",\n     \"regionName\": \"US_EAST_2\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  },\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 1\n     },\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"EU_WEST_1\"\n    },\n    {\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 2\n     },\n     \"priority\": 6,\n     \"providerName\": \"AZURE\",\n     \"regionName\": \"US_EAST_2\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  }\n ],\n \"tags\": []\n}"
         responses:
           - response_index: 10
@@ -90,7 +90,7 @@ steps:
             text: "true"
       - path: /api/atlas/v2/groups/{groupId}/clusters
         method: POST
-        version: '2024-10-23'
+        version: '2024-08-05'
         text: "{\n \"clusterType\": \"SHARDED\",\n \"configServerManagementMode\": \"FIXED_TO_DEDICATED\",\n \"labels\": [],\n \"mongoDBMajorVersion\": \"8.0\",\n \"name\": \"{clusterName}\",\n \"replicationSpecs\": [\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 1\n     },\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"EU_WEST_1\"\n    },\n    {\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 2\n     },\n     \"priority\": 6,\n     \"providerName\": \"AZURE\",\n     \"regionName\": \"US_EAST_2\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  },\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 1\n     },\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"EU_WEST_1\"\n    },\n    {\n     \"electableSpecs\": {\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 2\n     },\n     \"priority\": 6,\n     \"providerName\": \"AZURE\",\n     \"regionName\": \"US_EAST_2\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  }\n ],\n \"tags\": []\n}"
         responses:
           - response_index: 10
diff --git a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json
similarity index 100%
rename from internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json
rename to internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchema/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json
diff --git a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml
index 1eb5c71d27..23f1c5a4de 100644
--- a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml
+++ b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel.yaml
@@ -5,7 +5,7 @@ steps:
   - diff_requests:
       - path: /api/atlas/v2/groups/{groupId}/clusters
         method: POST
-        version: '2024-10-23'
+        version: '2024-08-05'
         text: "{\n \"backupEnabled\": false,\n \"clusterType\": \"SHARDED\",\n \"labels\": [],\n \"mongoDBMajorVersion\": \"7.0\",\n \"name\": \"{clusterName}\",\n \"replicationSpecs\": [\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 0\n     },\n     \"electableSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"US_EAST_1\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  },\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 0\n     },\n     \"electableSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"US_EAST_1\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  }\n ],\n \"tags\": []\n}"
         responses:
           - response_index: 10
@@ -90,7 +90,7 @@ steps:
             text: "true"
       - path: /api/atlas/v2/groups/{groupId}/clusters
         method: POST
-        version: '2024-10-23'
+        version: '2024-08-05'
         text: "{\n \"backupEnabled\": false,\n \"clusterType\": \"SHARDED\",\n \"labels\": [],\n \"mongoDBMajorVersion\": \"7.0\",\n \"name\": \"{clusterName}\",\n \"replicationSpecs\": [\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 0\n     },\n     \"electableSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"US_EAST_1\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  },\n  {\n   \"regionConfigs\": [\n    {\n     \"analyticsSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 0\n     },\n     \"electableSpecs\": {\n      \"diskSizeGB\": 50,\n      \"instanceSize\": \"M10\",\n      \"nodeCount\": 3\n     },\n     \"priority\": 7,\n     \"providerName\": \"AWS\",\n     \"regionName\": \"US_EAST_1\"\n    }\n   ],\n   \"zoneName\": \"ZoneName managed by Terraform\"\n  }\n ],\n \"tags\": []\n}"
         responses:
           - response_index: 10
diff --git a/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json b/internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json
similarity index 100%
rename from internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-10-23.json
rename to internal/service/advancedclustertpf/testdata/TestAccMockableAdvancedCluster_symmetricShardedOldSchemaDiskSizeGBAtElectableLevel/01_01_POST__api_atlas_v2_groups_{groupId}_clusters_2024-08-05.json