Skip to content

Commit 90e072d

Browse files
fix: Supporting advanced_cluster upgrade to dedicated with NMVe instance (#3725)
* supporting advanced_cluster tenant and flex upgrade to NMVe instance * adjusting mock files * Update .changelog/3725.txt Co-authored-by: Leo Antoli <[email protected]> --------- Co-authored-by: Leo Antoli <[email protected]>
1 parent afe73b7 commit 90e072d

File tree

6 files changed

+136
-197
lines changed

6 files changed

+136
-197
lines changed

.changelog/3725.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_advanced_cluster: Allows upgrade from tenant and flex cluster to dedicated NVMe with backup enabled
3+
```

internal/service/advancedcluster/resource_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func testAccAdvancedClusterFlexUpgrade(t *testing.T, projectID, clusterName, ins
6464
}
6565
if includeDedicated {
6666
steps = append(steps, resource.TestStep{
67-
Config: acc.ConfigBasicDedicated(projectID, clusterName, defaultZoneName),
68-
Check: checksBasicDedicated(projectID, clusterName, false),
67+
Config: acc.ConfigDedicatedNVMeBackupEnabled(projectID, clusterName, defaultZoneName),
68+
Check: checksDedicatedNVMeBackupEnabled(projectID, clusterName, false),
6969
})
7070
}
7171

@@ -102,8 +102,8 @@ func TestAccMockableAdvancedCluster_tenantUpgrade(t *testing.T) {
102102
Check: checkTenant(projectID, clusterName, true),
103103
},
104104
{
105-
Config: acc.ConfigBasicDedicated(projectID, clusterName, defaultZoneName),
106-
Check: checksBasicDedicated(projectID, clusterName, true),
105+
Config: acc.ConfigDedicatedNVMeBackupEnabled(projectID, clusterName, defaultZoneName),
106+
Check: checksDedicatedNVMeBackupEnabled(projectID, clusterName, true),
107107
},
108108
acc.TestStepImportCluster(resourceName),
109109
},
@@ -1437,12 +1437,14 @@ func checkTenant(projectID, name string, checkPlural bool) resource.TestCheckFun
14371437
pluralChecks...)
14381438
}
14391439

1440-
func checksBasicDedicated(projectID, name string, checkPlural bool) resource.TestCheckFunc {
1440+
func checksDedicatedNVMeBackupEnabled(projectID, name string, checkPlural bool) resource.TestCheckFunc {
14411441
originalChecks := checkTenant(projectID, name, checkPlural)
14421442
checkMap := map[string]string{
1443-
"replication_specs.0.region_configs.0.electable_specs.node_count": "3",
1444-
"replication_specs.0.region_configs.0.electable_specs.instance_size": "M10",
1445-
"replication_specs.0.region_configs.0.provider_name": "AWS",
1443+
"backup_enabled": "true",
1444+
"replication_specs.0.region_configs.0.electable_specs.node_count": "3",
1445+
"replication_specs.0.region_configs.0.electable_specs.instance_size": "M40_NVME",
1446+
"replication_specs.0.region_configs.0.electable_specs.ebs_volume_type": "PROVISIONED",
1447+
"replication_specs.0.region_configs.0.provider_name": "AWS",
14461448
}
14471449
return checkAggr(nil, checkMap, originalChecks)
14481450
}

internal/service/advancedcluster/resource_upgrade.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package advancedcluster
22

33
import (
44
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
5+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
56
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/flexcluster"
67
"go.mongodb.org/atlas-sdk/v20250312007/admin"
78
)
@@ -17,14 +18,19 @@ func getUpgradeTenantRequest(state, patch *admin.ClusterDescription20240805) *ad
1718
if oldProviderName != constant.TENANT || newProviderName == constant.TENANT {
1819
return nil
1920
}
20-
return &admin.LegacyAtlasTenantClusterUpgradeRequest{
21+
req := admin.LegacyAtlasTenantClusterUpgradeRequest{
2122
Name: state.GetName(),
2223
ProviderSettings: &admin.ClusterProviderSettings{
2324
ProviderName: newProviderName,
2425
RegionName: newRegion.RegionName,
2526
InstanceSizeName: newRegion.GetElectableSpecs().InstanceSize,
2627
},
2728
}
29+
if patch.GetBackupEnabled() {
30+
// ProviderBackupEnabled must be used instead of BackupEnabled for tenant upgrade request, details in CLOUDP-327109
31+
req.ProviderBackupEnabled = conversion.Pointer(true)
32+
}
33+
return &req
2834
}
2935

3036
func getUpgradeFlexToDedicatedRequest(state, patch *admin.ClusterDescription20240805) *admin.AtlasTenantClusterUpgradeRequest20240805 {
@@ -40,9 +46,15 @@ func getUpgradeFlexToDedicatedRequest(state, patch *admin.ClusterDescription2024
4046
if oldProviderName != flexcluster.FlexClusterType || newProviderName == flexcluster.FlexClusterType {
4147
return nil
4248
}
43-
return &admin.AtlasTenantClusterUpgradeRequest20240805{
49+
req := admin.AtlasTenantClusterUpgradeRequest20240805{
4450
Name: state.GetName(),
4551
ClusterType: state.ClusterType,
4652
ReplicationSpecs: patch.ReplicationSpecs,
4753
}
54+
55+
// checking for state value as a flex cluster can already have backup enabled
56+
if state.GetBackupEnabled() || patch.GetBackupEnabled() {
57+
req.BackupEnabled = conversion.Pointer(true)
58+
}
59+
return &req
4860
}

0 commit comments

Comments
 (0)