-
Notifications
You must be signed in to change notification settings - Fork 205
fix: Supporting advanced_cluster
upgrade to dedicated with NMVe instance
#3549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ad4f123
768761c
656404f
55c556b
99834f8
f988a45
bb39312
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:bug | ||
resource/mongodbatlas_advanced_cluster: Allow upgrade from tenant and flex cluster to dedicated NVMe with backup enabled | ||
``` | ||
|
||
```release-note:bug | ||
resource/mongodbatlas_advanced_cluster (preview provider 2.0.0): Allow upgrade from tenant and flex cluster to dedicated NVMe with backup enabled | ||
``` |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package advancedclustertpf | |||||||||||||
|
||||||||||||||
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/flexcluster" | ||||||||||||||
"go.mongodb.org/atlas-sdk/v20250312006/admin" | ||||||||||||||
) | ||||||||||||||
|
@@ -17,14 +18,20 @@ func getUpgradeTenantRequest(state, patch *admin.ClusterDescription20240805) *ad | |||||||||||||
if oldProviderName != constant.TENANT || newProviderName == constant.TENANT { | ||||||||||||||
return nil | ||||||||||||||
} | ||||||||||||||
return &admin.LegacyAtlasTenantClusterUpgradeRequest{ | ||||||||||||||
|
||||||||||||||
req := admin.LegacyAtlasTenantClusterUpgradeRequest{ | ||||||||||||||
Name: state.GetName(), | ||||||||||||||
ProviderSettings: &admin.ClusterProviderSettings{ | ||||||||||||||
ProviderName: newProviderName, | ||||||||||||||
RegionName: newRegion.RegionName, | ||||||||||||||
InstanceSizeName: newRegion.GetElectableSpecs().InstanceSize, | ||||||||||||||
}, | ||||||||||||||
} | ||||||||||||||
if patch.GetBackupEnabled() { | ||||||||||||||
// ProviderBackupEnabled must be used instead of BackupEnabled for tenant upgrade request, details in CLOUDP-327109 | ||||||||||||||
req.ProviderBackupEnabled = conversion.Pointer(true) | ||||||||||||||
} | ||||||||||||||
return &req | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func getUpgradeFlexToDedicatedRequest(state, patch *admin.ClusterDescription20240805) *admin.AtlasTenantClusterUpgradeRequest20240805 { | ||||||||||||||
|
@@ -40,9 +47,18 @@ func getUpgradeFlexToDedicatedRequest(state, patch *admin.ClusterDescription2024 | |||||||||||||
if oldProviderName != flexcluster.FlexClusterType || newProviderName == flexcluster.FlexClusterType { | ||||||||||||||
return nil | ||||||||||||||
} | ||||||||||||||
return &admin.AtlasTenantClusterUpgradeRequest20240805{ | ||||||||||||||
req := admin.AtlasTenantClusterUpgradeRequest20240805{ | ||||||||||||||
Name: state.GetName(), | ||||||||||||||
ClusterType: state.ClusterType, | ||||||||||||||
ReplicationSpecs: patch.ReplicationSpecs, | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
backupEnabled := state.BackupEnabled // a flex cluster can already have backup enabled | ||||||||||||||
if patch.BackupEnabled != nil { | ||||||||||||||
backupEnabled = patch.BackupEnabled | ||||||||||||||
} | ||||||||||||||
if backupEnabled != nil && *backupEnabled { | ||||||||||||||
Comment on lines
+56
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The backup enabled logic could be simplified. Consider using a more direct approach:
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||
req.BackupEnabled = conversion.Pointer(true) | ||||||||||||||
} | ||||||||||||||
return &req | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -207,21 +207,56 @@ func ConfigBasicDedicated(projectID, name, zoneName string) string { | |||||||||
%[3]s | ||||||||||
} | ||||||||||
} | ||||||||||
data "mongodbatlas_advanced_cluster" "test" { | ||||||||||
project_id = mongodbatlas_advanced_cluster.test.project_id | ||||||||||
name = mongodbatlas_advanced_cluster.test.name | ||||||||||
use_replication_spec_per_shard = true | ||||||||||
depends_on = [mongodbatlas_advanced_cluster.test] | ||||||||||
} | ||||||||||
|
||||||||||
data "mongodbatlas_advanced_clusters" "test" { | ||||||||||
use_replication_spec_per_shard = true | ||||||||||
project_id = mongodbatlas_advanced_cluster.test.project_id | ||||||||||
depends_on = [mongodbatlas_advanced_cluster.test] | ||||||||||
} | ||||||||||
`, projectID, name, zoneNameLine) | ||||||||||
%[4]s | ||||||||||
`, projectID, name, zoneNameLine, advancedClusterDataSources) | ||||||||||
} | ||||||||||
|
||||||||||
func ConfigDedicatedNVMeBackupEnabled(projectID, name, zoneName string) string { | ||||||||||
zoneNameLine := "" | ||||||||||
if zoneName != "" { | ||||||||||
zoneNameLine = fmt.Sprintf("zone_name = %q", zoneName) | ||||||||||
} | ||||||||||
return fmt.Sprintf(` | ||||||||||
resource "mongodbatlas_advanced_cluster" "test" { | ||||||||||
project_id = %[1]q | ||||||||||
name = %[2]q | ||||||||||
cluster_type = "REPLICASET" | ||||||||||
|
||||||||||
backup_enabled = true | ||||||||||
|
||||||||||
replication_specs { | ||||||||||
region_configs { | ||||||||||
priority = 7 | ||||||||||
provider_name = "AWS" | ||||||||||
region_name = "US_EAST_1" | ||||||||||
electable_specs { | ||||||||||
instance_size = "M40_NVME" | ||||||||||
ebs_volume_type = "PROVISIONED" | ||||||||||
node_count = 3 | ||||||||||
Comment on lines
+234
to
+235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is inconsistent. All three fields should use the same indentation level as the surrounding code.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
} | ||||||||||
} | ||||||||||
%[3]s | ||||||||||
} | ||||||||||
} | ||||||||||
%[4]s | ||||||||||
`, projectID, name, zoneNameLine, advancedClusterDataSources) | ||||||||||
} | ||||||||||
|
||||||||||
const advancedClusterDataSources = ` | ||||||||||
data "mongodbatlas_advanced_cluster" "test" { | ||||||||||
project_id = mongodbatlas_advanced_cluster.test.project_id | ||||||||||
name = mongodbatlas_advanced_cluster.test.name | ||||||||||
use_replication_spec_per_shard = true | ||||||||||
depends_on = [mongodbatlas_advanced_cluster.test] | ||||||||||
} | ||||||||||
|
||||||||||
data "mongodbatlas_advanced_clusters" "test" { | ||||||||||
use_replication_spec_per_shard = true | ||||||||||
project_id = mongodbatlas_advanced_cluster.test.project_id | ||||||||||
depends_on = [mongodbatlas_advanced_cluster.test] | ||||||||||
} | ||||||||||
` | ||||||||||
|
||||||||||
func JoinQuotedStrings(list []string) string { | ||||||||||
quoted := make([]string, len(list)) | ||||||||||
for i, item := range list { | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
req.BackupEnabled = backupEnabled
?Or do we want to avoid setting it if it is
false
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would not make a difference, just thought of keeping the upgrade request compact for the regular cases