From 24b0e979091eaf18ec4a7541c47308198c2db9f1 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Fri, 17 Jan 2025 09:52:16 +0000 Subject: [PATCH 1/7] test: Updates importIgnoredFields function to handle dynamic replication specs --- .../resource_advanced_cluster_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 7f5dd0b664..f9a877e831 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -1190,7 +1190,7 @@ func TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate(t *testing.T) { Config: configBasicReplicaset(t, projectID, clusterName, fullUpdate), Check: checksUpdate, }, - acc.TestStepImportCluster(resourceName, importIgnoredFields()...), + acc.TestStepImportCluster(resourceName, importIgnoredFields(1)...), }, }) } @@ -1233,7 +1233,7 @@ func TestAccMockableAdvancedCluster_shardedAddAnalyticsAndAutoScaling(t *testing Config: configSharded(t, projectID, clusterName, true), Check: checksUpdated, }, - acc.TestStepImportCluster(resourceName, importIgnoredFields()...), + acc.TestStepImportCluster(resourceName, importIgnoredFields(2)...), }, }) } @@ -2782,13 +2782,17 @@ func configFCVPinning(t *testing.T, orgID, projectName, clusterName string, pinn `, orgID, projectName, clusterName, mongoDBMajorVersion, pinnedFCVAttr)) + dataSourcesTFNewSchema } -func importIgnoredFields() []string { +func importIgnoredFields(replicationSpecs int) []string { if config.AdvancedClusterV2Schema() { return []string{} } - return []string{ - "replication_specs.0.region_configs.0.read_only_specs", - "replication_specs.0.region_configs.0.analytics_specs", - "replication_specs.0.region_configs.0.electable_specs.0.ebs_volume_type", + ignored := []string{} + for i := range replicationSpecs { + ignored = append(ignored, + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs.0.ebs_volume_type", i), + ) } + return ignored } From a3c5dc552019d679431c5577797e780e9476811e Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:58:34 +0100 Subject: [PATCH 2/7] improve naming, reverse condition --- .../resource_advanced_cluster_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index f9a877e831..c8bd260170 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -1190,7 +1190,7 @@ func TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate(t *testing.T) { Config: configBasicReplicaset(t, projectID, clusterName, fullUpdate), Check: checksUpdate, }, - acc.TestStepImportCluster(resourceName, importIgnoredFields(1)...), + acc.TestStepImportCluster(resourceName, importIgnoredFieldsSetOnlyInV2Schema(1)...), }, }) } @@ -1233,7 +1233,7 @@ func TestAccMockableAdvancedCluster_shardedAddAnalyticsAndAutoScaling(t *testing Config: configSharded(t, projectID, clusterName, true), Check: checksUpdated, }, - acc.TestStepImportCluster(resourceName, importIgnoredFields(2)...), + acc.TestStepImportCluster(resourceName, importIgnoredFieldsSetOnlyInV2Schema(2)...), }, }) } @@ -2782,12 +2782,12 @@ func configFCVPinning(t *testing.T, orgID, projectName, clusterName string, pinn `, orgID, projectName, clusterName, mongoDBMajorVersion, pinnedFCVAttr)) + dataSourcesTFNewSchema } -func importIgnoredFields(replicationSpecs int) []string { - if config.AdvancedClusterV2Schema() { - return []string{} +func importIgnoredFieldsSetOnlyInV2Schema(replicationSpecsCount int) []string { + if !config.AdvancedClusterV2Schema() { + return nil } - ignored := []string{} - for i := range replicationSpecs { + var ignored []string + for i := range replicationSpecsCount { ignored = append(ignored, fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), From 2426d2e5de5d64be0a3eb468e4805767c10f39d0 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:02:39 +0100 Subject: [PATCH 3/7] ignore all changing attributes --- .../resource_advanced_cluster_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index c8bd260170..b800145d9c 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -2789,9 +2789,22 @@ func importIgnoredFieldsSetOnlyInV2Schema(replicationSpecsCount int) []string { var ignored []string for i := range replicationSpecsCount { ignored = append(ignored, - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.#", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.%%", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.disk_iops", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.disk_size_gb", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.ebs_volume_type", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.instance_size", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.node_count", i), fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs.0.ebs_volume_type", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs.0.ebs_volume_type", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.#", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.%%", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.disk_iops", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.disk_size_gb", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.ebs_volume_type", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.instance_size", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.node_count", i), ) } return ignored From 08b40ee3240e762ecc4b8419d1facc4f25036314 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Sun, 19 Jan 2025 11:16:34 +0100 Subject: [PATCH 4/7] clarify tests --- .../resource_advanced_cluster_test.go | 31 +++++++------------ internal/testutil/acc/advanced_cluster.go | 4 +-- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index b800145d9c..10a745d0e6 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -1190,7 +1190,7 @@ func TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate(t *testing.T) { Config: configBasicReplicaset(t, projectID, clusterName, fullUpdate), Check: checksUpdate, }, - acc.TestStepImportCluster(resourceName, importIgnoredFieldsSetOnlyInV2Schema(1)...), + acc.TestStepImportCluster(resourceName, importIgnoredPrefixFieldsInV2Schema(1)...), }, }) } @@ -1233,7 +1233,7 @@ func TestAccMockableAdvancedCluster_shardedAddAnalyticsAndAutoScaling(t *testing Config: configSharded(t, projectID, clusterName, true), Check: checksUpdated, }, - acc.TestStepImportCluster(resourceName, importIgnoredFieldsSetOnlyInV2Schema(2)...), + acc.TestStepImportCluster(resourceName, importIgnoredPrefixFieldsInV2Schema(2)...), }, }) } @@ -2782,29 +2782,20 @@ func configFCVPinning(t *testing.T, orgID, projectName, clusterName string, pinn `, orgID, projectName, clusterName, mongoDBMajorVersion, pinnedFCVAttr)) + dataSourcesTFNewSchema } -func importIgnoredFieldsSetOnlyInV2Schema(replicationSpecsCount int) []string { - if !config.AdvancedClusterV2Schema() { +// importIgnoredPrefixFieldsInV2Schema ignores import fields in SDKv2. +// analytics|electable|read_only are only set in state in SDKv2 if present in the definition. +// However, as import doesn't have a previous state to compare with, import will always fill them. +// This will make these fields differ in the state, although the plan change won't be shown to the user as they're computed values. +func importIgnoredPrefixFieldsInV2Schema(replicationSpecsCount int) []string { + if config.AdvancedClusterV2Schema() { return nil } var ignored []string for i := range replicationSpecsCount { ignored = append(ignored, - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.#", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.%%", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.disk_iops", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.disk_size_gb", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.ebs_volume_type", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.instance_size", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs.0.node_count", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs.0.ebs_volume_type", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs.0.ebs_volume_type", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.#", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.%%", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.disk_iops", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.disk_size_gb", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.ebs_volume_type", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.instance_size", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs.0.node_count", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), ) } return ignored diff --git a/internal/testutil/acc/advanced_cluster.go b/internal/testutil/acc/advanced_cluster.go index 46635d1258..494bbff1a7 100644 --- a/internal/testutil/acc/advanced_cluster.go +++ b/internal/testutil/acc/advanced_cluster.go @@ -42,14 +42,14 @@ var ( } ) -func TestStepImportCluster(resourceName string, ignoredFields ...string) resource.TestStep { +func TestStepImportCluster(resourceName string, ignoredPrefixFields ...string) resource.TestStep { return resource.TestStep{ ResourceName: resourceName, ImportStateIdFunc: ImportStateIDFuncProjectIDClusterName(resourceName, "project_id", "name"), ImportState: true, ImportStateVerify: true, ImportStateVerifyIdentifierAttribute: "name", - ImportStateVerifyIgnore: ignoredFields, + ImportStateVerifyIgnore: ignoredPrefixFields, } } From 781aa1a1a5e4f6bac6d0145953bd8cdc665bb6f6 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Sun, 19 Jan 2025 18:00:19 +0100 Subject: [PATCH 5/7] refactor acc.TestStepImportCluster --- .../resource_advanced_cluster_test.go | 33 ++++--------------- .../service/cluster/resource_cluster_test.go | 2 +- internal/testutil/acc/advanced_cluster.go | 21 ++++++++++-- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 10a745d0e6..36d9850639 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -193,7 +193,7 @@ func replicaSetAWSProviderTestCase(t *testing.T, isAcc bool) resource.TestCase { Config: configReplicaSetAWSProvider(t, isAcc, projectID, clusterName, 50, 5), Check: checkReplicaSetAWSProvider(isAcc, projectID, clusterName, 50, 5, true, true), }, - acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"), + acc.TestStepImportCluster(resourceName), }, } } @@ -224,7 +224,7 @@ func replicaSetMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase { Config: configReplicaSetMultiCloud(t, isAcc, orgID, projectName, clusterNameUpdated), Check: checkReplicaSetMultiCloud(isAcc, clusterNameUpdated, 3), }, - acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"), + acc.TestStepImportCluster(resourceName), }, } } @@ -253,7 +253,7 @@ func singleShardedMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase Config: configShardedOldSchemaMultiCloud(t, isAcc, projectID, clusterNameUpdated, 1, "M10", nil), Check: checkShardedOldSchemaMultiCloud(isAcc, clusterNameUpdated, 1, "M10", true, nil), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, } } @@ -282,7 +282,7 @@ func TestAccClusterAdvancedCluster_unpausedToPaused(t *testing.T) { Config: configSingleProviderPaused(t, true, projectID, clusterName, true, anotherInstanceSize), ExpectError: regexp.MustCompile("CANNOT_UPDATE_PAUSED_CLUSTER"), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, }) } @@ -313,7 +313,7 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) { { Config: configSingleProviderPaused(t, true, projectID, clusterName, false, instanceSize), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, }) } @@ -1190,7 +1190,7 @@ func TestAccMockableAdvancedCluster_replicasetAdvConfigUpdate(t *testing.T) { Config: configBasicReplicaset(t, projectID, clusterName, fullUpdate), Check: checksUpdate, }, - acc.TestStepImportCluster(resourceName, importIgnoredPrefixFieldsInV2Schema(1)...), + acc.TestStepImportCluster(resourceName), }, }) } @@ -1233,7 +1233,7 @@ func TestAccMockableAdvancedCluster_shardedAddAnalyticsAndAutoScaling(t *testing Config: configSharded(t, projectID, clusterName, true), Check: checksUpdated, }, - acc.TestStepImportCluster(resourceName, importIgnoredPrefixFieldsInV2Schema(2)...), + acc.TestStepImportCluster(resourceName), }, }) } @@ -2781,22 +2781,3 @@ func configFCVPinning(t *testing.T, orgID, projectName, clusterName string, pinn `, orgID, projectName, clusterName, mongoDBMajorVersion, pinnedFCVAttr)) + dataSourcesTFNewSchema } - -// importIgnoredPrefixFieldsInV2Schema ignores import fields in SDKv2. -// analytics|electable|read_only are only set in state in SDKv2 if present in the definition. -// However, as import doesn't have a previous state to compare with, import will always fill them. -// This will make these fields differ in the state, although the plan change won't be shown to the user as they're computed values. -func importIgnoredPrefixFieldsInV2Schema(replicationSpecsCount int) []string { - if config.AdvancedClusterV2Schema() { - return nil - } - var ignored []string - for i := range replicationSpecsCount { - ignored = append(ignored, - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), - ) - } - return ignored -} diff --git a/internal/service/cluster/resource_cluster_test.go b/internal/service/cluster/resource_cluster_test.go index 929fc38bb6..1a46736dcb 100644 --- a/internal/service/cluster/resource_cluster_test.go +++ b/internal/service/cluster/resource_cluster_test.go @@ -80,7 +80,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase { resource.TestCheckResourceAttr(resourceName, "auto_scaling_disk_gb_enabled", "false"), ), }, - acc.TestStepImportCluster(resourceName, "cloud_backup", "retain_backups_enabled"), + acc.TestStepImportCluster(resourceName, "cloud_backup"), }, } } diff --git a/internal/testutil/acc/advanced_cluster.go b/internal/testutil/acc/advanced_cluster.go index 494bbff1a7..6d643f65e6 100644 --- a/internal/testutil/acc/advanced_cluster.go +++ b/internal/testutil/acc/advanced_cluster.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -42,14 +43,30 @@ var ( } ) -func TestStepImportCluster(resourceName string, ignoredPrefixFields ...string) resource.TestStep { +func TestStepImportCluster(resourceName string, ignorePrefixFields ...string) resource.TestStep { + ignorePrefixFields = append(ignorePrefixFields, + "retain_backups_enabled", // This field is TF specific and not returned by Atlas, so Import can't fill it in. + ) + + // analytics|electable|read_only are only set in state in SDKv2 if present in the definition. + // However, as import doesn't have a previous state to compare with, import will always fill them. + // This will make these fields differ in the state, although the plan change won't be shown to the user as they're computed values. + if !config.AdvancedClusterV2Schema() { + for i := range 2 { // tests have at most 2 replication_configs + ignorePrefixFields = append(ignorePrefixFields, + fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs", i), + fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), + ) + } + } return resource.TestStep{ ResourceName: resourceName, ImportStateIdFunc: ImportStateIDFuncProjectIDClusterName(resourceName, "project_id", "name"), ImportState: true, ImportStateVerify: true, ImportStateVerifyIdentifierAttribute: "name", - ImportStateVerifyIgnore: ignoredPrefixFields, + ImportStateVerifyIgnore: ignorePrefixFields, } } From 29fe7159d9a95179d45d766f19a534f20b8ef0c5 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Sun, 19 Jan 2025 20:33:59 +0100 Subject: [PATCH 6/7] revert unrelated changes --- .../advancedcluster/resource_advanced_cluster_test.go | 10 +++++----- internal/service/cluster/resource_cluster_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 36d9850639..9c88daf656 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -193,7 +193,7 @@ func replicaSetAWSProviderTestCase(t *testing.T, isAcc bool) resource.TestCase { Config: configReplicaSetAWSProvider(t, isAcc, projectID, clusterName, 50, 5), Check: checkReplicaSetAWSProvider(isAcc, projectID, clusterName, 50, 5, true, true), }, - acc.TestStepImportCluster(resourceName), + acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"), }, } } @@ -224,7 +224,7 @@ func replicaSetMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase { Config: configReplicaSetMultiCloud(t, isAcc, orgID, projectName, clusterNameUpdated), Check: checkReplicaSetMultiCloud(isAcc, clusterNameUpdated, 3), }, - acc.TestStepImportCluster(resourceName), + acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"), }, } } @@ -253,7 +253,7 @@ func singleShardedMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase Config: configShardedOldSchemaMultiCloud(t, isAcc, projectID, clusterNameUpdated, 1, "M10", nil), Check: checkShardedOldSchemaMultiCloud(isAcc, clusterNameUpdated, 1, "M10", true, nil), }, - acc.TestStepImportCluster(resourceName), + acc.TestStepImportCluster(resourceName, "replication_specs"), }, } } @@ -282,7 +282,7 @@ func TestAccClusterAdvancedCluster_unpausedToPaused(t *testing.T) { Config: configSingleProviderPaused(t, true, projectID, clusterName, true, anotherInstanceSize), ExpectError: regexp.MustCompile("CANNOT_UPDATE_PAUSED_CLUSTER"), }, - acc.TestStepImportCluster(resourceName), + acc.TestStepImportCluster(resourceName, "replication_specs"), }, }) } @@ -313,7 +313,7 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) { { Config: configSingleProviderPaused(t, true, projectID, clusterName, false, instanceSize), }, - acc.TestStepImportCluster(resourceName), + acc.TestStepImportCluster(resourceName, "replication_specs"), }, }) } diff --git a/internal/service/cluster/resource_cluster_test.go b/internal/service/cluster/resource_cluster_test.go index 1a46736dcb..929fc38bb6 100644 --- a/internal/service/cluster/resource_cluster_test.go +++ b/internal/service/cluster/resource_cluster_test.go @@ -80,7 +80,7 @@ func basicTestCase(tb testing.TB) *resource.TestCase { resource.TestCheckResourceAttr(resourceName, "auto_scaling_disk_gb_enabled", "false"), ), }, - acc.TestStepImportCluster(resourceName, "cloud_backup"), + acc.TestStepImportCluster(resourceName, "cloud_backup", "retain_backups_enabled"), }, } } From f64edbbbe4b524741dbab77ac3980ec44ddb4f71 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Mon, 20 Jan 2025 07:22:30 +0100 Subject: [PATCH 7/7] ignore all replication_specs --- .../advancedcluster/resource_advanced_cluster_test.go | 8 ++++---- internal/testutil/acc/advanced_cluster.go | 10 ++-------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/internal/service/advancedcluster/resource_advanced_cluster_test.go b/internal/service/advancedcluster/resource_advanced_cluster_test.go index 9c88daf656..aae7e8cfe7 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster_test.go +++ b/internal/service/advancedcluster/resource_advanced_cluster_test.go @@ -224,7 +224,7 @@ func replicaSetMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase { Config: configReplicaSetMultiCloud(t, isAcc, orgID, projectName, clusterNameUpdated), Check: checkReplicaSetMultiCloud(isAcc, clusterNameUpdated, 3), }, - acc.TestStepImportCluster(resourceName, "replication_specs", "retain_backups_enabled"), + acc.TestStepImportCluster(resourceName), }, } } @@ -253,7 +253,7 @@ func singleShardedMultiCloudTestCase(t *testing.T, isAcc bool) resource.TestCase Config: configShardedOldSchemaMultiCloud(t, isAcc, projectID, clusterNameUpdated, 1, "M10", nil), Check: checkShardedOldSchemaMultiCloud(isAcc, clusterNameUpdated, 1, "M10", true, nil), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, } } @@ -282,7 +282,7 @@ func TestAccClusterAdvancedCluster_unpausedToPaused(t *testing.T) { Config: configSingleProviderPaused(t, true, projectID, clusterName, true, anotherInstanceSize), ExpectError: regexp.MustCompile("CANNOT_UPDATE_PAUSED_CLUSTER"), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, }) } @@ -313,7 +313,7 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) { { Config: configSingleProviderPaused(t, true, projectID, clusterName, false, instanceSize), }, - acc.TestStepImportCluster(resourceName, "replication_specs"), + acc.TestStepImportCluster(resourceName), }, }) } diff --git a/internal/testutil/acc/advanced_cluster.go b/internal/testutil/acc/advanced_cluster.go index 6d643f65e6..6e7371481f 100644 --- a/internal/testutil/acc/advanced_cluster.go +++ b/internal/testutil/acc/advanced_cluster.go @@ -48,17 +48,11 @@ func TestStepImportCluster(resourceName string, ignorePrefixFields ...string) re "retain_backups_enabled", // This field is TF specific and not returned by Atlas, so Import can't fill it in. ) - // analytics|electable|read_only are only set in state in SDKv2 if present in the definition. + // auto_scaling & specs (electable_specs, read_only_specs, etc.) are only set in state in SDKv2 if present in the definition. // However, as import doesn't have a previous state to compare with, import will always fill them. // This will make these fields differ in the state, although the plan change won't be shown to the user as they're computed values. if !config.AdvancedClusterV2Schema() { - for i := range 2 { // tests have at most 2 replication_configs - ignorePrefixFields = append(ignorePrefixFields, - fmt.Sprintf("replication_specs.%d.region_configs.0.analytics_specs", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.electable_specs", i), - fmt.Sprintf("replication_specs.%d.region_configs.0.read_only_specs", i), - ) - } + ignorePrefixFields = append(ignorePrefixFields, "replication_specs") } return resource.TestStep{ ResourceName: resourceName,