Skip to content

Commit fab968b

Browse files
fix: Avoid inconsistent result after apply when transitioning from replica set to sharded (#3146)
* avoid inconsistent result after apply when transitioning from replica set to sharded * adding test for replica set to sharded * include cluster type in migration test
1 parent c74b50b commit fab968b

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

internal/service/advancedcluster/resource_advanced_cluster_migration_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ func TestMigAdvancedCluster_replicaSetAWSProviderUpdate(t *testing.T) {
5252
Steps: []resource.TestStep{
5353
{
5454
ExternalProviders: acc.ExternalProviders(versionBeforeISSRelease),
55-
Config: configReplicaSetAWSProvider(t, false, ReplicaSetAWSConfig{
55+
Config: configAWSProvider(t, false, ReplicaSetAWSConfig{
5656
ProjectID: projectID,
5757
ClusterName: clusterName,
58+
ClusterType: "REPLICASET",
5859
DiskSizeGB: 60,
5960
NodeCountElectable: 3,
6061
WithAnalyticsSpecs: true,
@@ -63,9 +64,10 @@ func TestMigAdvancedCluster_replicaSetAWSProviderUpdate(t *testing.T) {
6364
},
6465
{
6566
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
66-
Config: configReplicaSetAWSProvider(t, false, ReplicaSetAWSConfig{
67+
Config: configAWSProvider(t, false, ReplicaSetAWSConfig{
6768
ProjectID: projectID,
6869
ClusterName: clusterName,
70+
ClusterType: "REPLICASET",
6971
DiskSizeGB: 60,
7072
NodeCountElectable: 5,
7173
WithAnalyticsSpecs: true,

internal/service/advancedcluster/resource_advanced_cluster_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,38 @@ func replicaSetAWSProviderTestCase(t *testing.T, isAcc bool) resource.TestCase {
203203
CheckDestroy: acc.CheckDestroyCluster,
204204
Steps: []resource.TestStep{
205205
{
206-
Config: configReplicaSetAWSProvider(t, isAcc, ReplicaSetAWSConfig{
206+
Config: configAWSProvider(t, isAcc, ReplicaSetAWSConfig{
207207
ProjectID: projectID,
208208
ClusterName: clusterName,
209+
ClusterType: "REPLICASET",
209210
DiskSizeGB: 60,
210211
NodeCountElectable: 3,
211212
WithAnalyticsSpecs: true,
212213
}),
213214
Check: checkReplicaSetAWSProvider(isAcc, projectID, clusterName, 60, 3, true, true),
214215
},
215216
{
216-
Config: configReplicaSetAWSProvider(t, isAcc, ReplicaSetAWSConfig{
217+
Config: configAWSProvider(t, isAcc, ReplicaSetAWSConfig{
217218
ProjectID: projectID,
218219
ClusterName: clusterName,
220+
ClusterType: "REPLICASET",
219221
DiskSizeGB: 50,
220222
NodeCountElectable: 5,
221223
WithAnalyticsSpecs: false, // removed as part of other updates, computed value is expected to be the same
222224
}),
223225
Check: checkReplicaSetAWSProvider(isAcc, projectID, clusterName, 50, 5, true, true),
224226
},
227+
{ // testing transition from replica set to sharded cluster
228+
Config: configAWSProvider(t, isAcc, ReplicaSetAWSConfig{
229+
ProjectID: projectID,
230+
ClusterName: clusterName,
231+
ClusterType: "SHARDED",
232+
DiskSizeGB: 50,
233+
NodeCountElectable: 5,
234+
WithAnalyticsSpecs: false,
235+
}),
236+
Check: checkReplicaSetAWSProvider(isAcc, projectID, clusterName, 50, 5, true, true),
237+
},
225238
acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"),
226239
},
227240
}
@@ -1772,12 +1785,13 @@ func checkKeyValueBlocksPreviewProviderV2(isAcc, includeDataSources bool, blockN
17721785
type ReplicaSetAWSConfig struct {
17731786
ProjectID string
17741787
ClusterName string
1788+
ClusterType string
17751789
DiskSizeGB int
17761790
NodeCountElectable int
17771791
WithAnalyticsSpecs bool
17781792
}
17791793

1780-
func configReplicaSetAWSProvider(t *testing.T, isAcc bool, configInfo ReplicaSetAWSConfig) string {
1794+
func configAWSProvider(t *testing.T, isAcc bool, configInfo ReplicaSetAWSConfig) string {
17811795
t.Helper()
17821796
analyticsSpecs := ""
17831797
if configInfo.WithAnalyticsSpecs {
@@ -1791,24 +1805,24 @@ func configReplicaSetAWSProvider(t *testing.T, isAcc bool, configInfo ReplicaSet
17911805
resource "mongodbatlas_advanced_cluster" "test" {
17921806
project_id = %[1]q
17931807
name = %[2]q
1794-
cluster_type = "REPLICASET"
1808+
cluster_type = %[3]q
17951809
retain_backups_enabled = "true"
1796-
disk_size_gb = %[3]d
1810+
disk_size_gb = %[4]d
17971811
17981812
replication_specs {
17991813
region_configs {
18001814
electable_specs {
18011815
instance_size = "M10"
1802-
node_count = %[4]d
1816+
node_count = %[5]d
18031817
}
1804-
%[5]s
1818+
%[6]s
18051819
provider_name = "AWS"
18061820
priority = 7
18071821
region_name = "US_WEST_2"
18081822
}
18091823
}
18101824
}
1811-
`, configInfo.ProjectID, configInfo.ClusterName, configInfo.DiskSizeGB, configInfo.NodeCountElectable, analyticsSpecs)) + dataSourcesTFOldSchema
1825+
`, configInfo.ProjectID, configInfo.ClusterName, configInfo.ClusterType, configInfo.DiskSizeGB, configInfo.NodeCountElectable, analyticsSpecs)) + dataSourcesTFOldSchema
18121826
}
18131827

18141828
func checkReplicaSetAWSProvider(isAcc bool, projectID, name string, diskSizeGB, nodeCountElectable int, checkDiskSizeGBInnerLevel, checkExternalID bool) resource.TestCheckFunc {

internal/service/advancedclustertpf/plan_modifier.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var (
1919
"replication_specs": {},
2020
"mongo_db_major_version": {"mongo_db_version"},
2121
"tls_cipher_config_mode": {"custom_openssl_cipher_config_tls12"},
22+
"cluster_type": {"config_server_management_mode", "config_server_type"}, // computed values of config server change when REPLICA_SET changes to SHARDED
2223
}
2324
attributeReplicationSpecChangeMapping = map[string][]string{
2425
// All these fields can exist in specs that are computed, therefore, it is not safe to use them when they have changed.

0 commit comments

Comments
 (0)