Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/acceptance-tests-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,10 @@ jobs:
MONGODB_ATLAS_LAST_1X_VERSION: ${{ inputs.mongodb_atlas_last_1x_version }}
MONGODB_ATLAS_TEST_SDKV2_TO_TPF: 'false'
ACCTEST_REGEX_RUN: '^TestV1xMig'
ACCTEST_PACKAGES: ./internal/service/advancedcluster
# Include TestV1xMigBackupRSCloudBackupSchedule_copySettings.
ACCTEST_PACKAGES: |
./internal/service/advancedcluster
./internal/service/cloudbackupschedule
run: make testacc

advanced_cluster_sa_mig:
Expand Down Expand Up @@ -706,7 +709,6 @@ jobs:
env:
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ inputs.mongodb_atlas_project_owner_id }}
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
MONGODB_ATLAS_LAST_1X_VERSION: ${{ inputs.mongodb_atlas_last_1x_version }}
AWS_REGION: ${{ vars.AWS_REGION_LOWERCASE }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }}
AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }}
Expand Down
36 changes: 11 additions & 25 deletions internal/service/advancedcluster/resource_migration_v1x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

var versionBeforeTPFGARelease = os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
var (
versionBeforeTPFGARelease = os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
isSDKv2 = acc.IsTestSDKv2ToTPF()
)

func TestV1xMigClusterAdvancedClusterConfig_geoShardedNewSchema(t *testing.T) {
projectID, clusterName := acc.ProjectIDExecutionWithCluster(t, 8)
isSDKv2 := acc.IsTestSDKv2ToTPF()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -122,10 +123,8 @@ func checkGeoShardedTransitionOldToNewSchema(isTPF, useNewSchema bool) resource.

func TestV1xMigAdvancedCluster_oldToNewSchemaWithAutoscalingEnabled(t *testing.T) {
projectID, clusterName := acc.ProjectIDExecutionWithCluster(t, 8)
isSDKv2 := acc.IsTestSDKv2ToTPF()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasicSleep(t, nil, projectID, clusterName); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand All @@ -151,11 +150,8 @@ func TestV1xMigAdvancedCluster_oldToNewSchemaWithAutoscalingEnabled(t *testing.T

func TestV1xMigAdvancedCluster_shardedNewSchema(t *testing.T) {
projectID, clusterName := acc.ProjectIDExecutionWithCluster(t, 8)
versionBeforeTPFGARelease := os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
isSDKv2 := acc.IsTestSDKv2ToTPF()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -277,11 +273,8 @@ func checkShardedTransitionOldToNewSchema(isTPF, useNewSchema bool) resource.Tes

func TestV1xMigAdvancedCluster_geoShardedMigrationFromOldToNewSchema(t *testing.T) {
projectID, clusterName := acc.ProjectIDExecutionWithCluster(t, 8)
versionBeforeTPFGARelease := os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
isSDKv2 := acc.IsTestSDKv2ToTPF()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand All @@ -305,14 +298,9 @@ func TestV1xMigAdvancedCluster_geoShardedMigrationFromOldToNewSchema(t *testing.
}

func TestV1xMigAdvancedCluster_replicaSetAWSProvider(t *testing.T) {
var (
projectID, clusterName = acc.ProjectIDExecutionWithCluster(t, 6)
versionBeforeTPFGARelease = os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
isSDKv2 = acc.IsTestSDKv2ToTPF()
)

projectID, clusterName := acc.ProjectIDExecutionWithCluster(t, 6)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasicSleep(t, nil, projectID, clusterName); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -352,11 +340,9 @@ func TestV1xMigAdvancedCluster_replicaSetMultiCloud(t *testing.T) {
var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName, clusterName = acc.ProjectIDExecutionWithCluster(t, 6)
isSDKv2 = acc.IsTestSDKv2ToTPF()
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t); mig.PreCheckLast1XVersion(t) },
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t) },
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cloudbackupschedule_test

import (
"os"
"testing"

"go.mongodb.org/atlas-sdk/v20250312008/admin"
Expand Down Expand Up @@ -50,89 +49,6 @@ func TestMigBackupRSCloudBackupSchedule_basic(t *testing.T) {
})
}

func TestMigBackupRSCloudBackupSchedule_copySettings(t *testing.T) {
mig.SkipIfVersionBelow(t, "1.29.0") // version when advanced cluster TPF was introduced
var (
lastVersionRepSpecID = os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{
CloudBackup: true,
ReplicationSpecs: []acc.ReplicationSpecRequest{
{Region: "US_EAST_2"},
},
PitEnabled: true, // you cannot copy oplogs when pit is not enabled
})
clusterName = clusterInfo.Name
terraformStr = clusterInfo.TerraformStr
clusterResourceName = clusterInfo.ResourceName
projectID = clusterInfo.ProjectID
copySettingsConfigWithRepSpecID = configCopySettings(terraformStr, projectID, clusterResourceName, false, true, &admin.DiskBackupSnapshotSchedule20240805{
ReferenceHourOfDay: conversion.Pointer(3),
ReferenceMinuteOfHour: conversion.Pointer(45),
RestoreWindowDays: conversion.Pointer(1),
})
copySettingsConfigWithZoneID = configCopySettings(terraformStr, projectID, clusterResourceName, false, false, &admin.DiskBackupSnapshotSchedule20240805{
ReferenceHourOfDay: conversion.Pointer(3),
ReferenceMinuteOfHour: conversion.Pointer(45),
RestoreWindowDays: conversion.Pointer(1),
})
checkMap = map[string]string{
"cluster_name": clusterName,
"reference_hour_of_day": "3",
"reference_minute_of_hour": "45",
"restore_window_days": "1",
"policy_item_hourly.#": "1",
"policy_item_daily.#": "1",
"policy_item_weekly.#": "1",
"policy_item_monthly.#": "1",
"policy_item_yearly.#": "1",
"policy_item_hourly.0.frequency_interval": "1",
"policy_item_hourly.0.retention_unit": "days",
"policy_item_hourly.0.retention_value": "1",
"policy_item_daily.0.frequency_interval": "1",
"policy_item_daily.0.retention_unit": "days",
"policy_item_daily.0.retention_value": "2",
"policy_item_weekly.0.frequency_interval": "4",
"policy_item_weekly.0.retention_unit": "weeks",
"policy_item_weekly.0.retention_value": "3",
"policy_item_monthly.0.frequency_interval": "5",
"policy_item_monthly.0.retention_unit": "months",
"policy_item_monthly.0.retention_value": "4",
"policy_item_yearly.0.frequency_interval": "1",
"policy_item_yearly.0.retention_unit": "years",
"policy_item_yearly.0.retention_value": "1",
}
copySettingsChecks = map[string]string{
"copy_settings.#": "1",
"copy_settings.0.cloud_provider": "AWS",
"copy_settings.0.region_name": "US_EAST_1",
"copy_settings.0.should_copy_oplogs": "true",
}
)

checksDefault := acc.AddAttrChecks(resourceName, []resource.TestCheckFunc{checkExists(resourceName)}, checkMap)
checksCreate := acc.AddAttrChecks(resourceName, checksDefault, copySettingsChecks)
checksCreateWithReplicationSpecID := acc.AddAttrSetChecks(resourceName, checksCreate, "copy_settings.0.replication_spec_id")
checksUpdateWithZoneID := acc.AddAttrSetChecks(resourceName, checksCreate, "copy_settings.0.zone_id")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasicSleep(t); mig.PreCheckOldPreviewEnv(t) },
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: acc.ExternalProviders(lastVersionRepSpecID),
Config: copySettingsConfigWithRepSpecID,
Check: resource.ComposeAggregateTestCheckFunc(checksCreateWithReplicationSpecID...),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: copySettingsConfigWithZoneID,
Check: resource.ComposeAggregateTestCheckFunc(checksUpdateWithZoneID...),
},
mig.TestStepCheckEmptyPlan(copySettingsConfigWithZoneID),
},
})
}

func TestMigBackupRSCloudBackupSchedule_export(t *testing.T) {
mig.SkipIfVersionBelow(t, "2.0.0") // in 2.0.0 we made auto_export_enabled and export fields optional only
var (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cloudbackupschedule_test

import (
"os"
"testing"

"go.mongodb.org/atlas-sdk/v20250312008/admin"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestV1xMigBackupRSCloudBackupSchedule_copySettings(t *testing.T) {
mig.SkipIfVersionBelow(t, "1.29.0") // version when advanced cluster TPF was introduced
var (
lastVersionRepSpecID = os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION")
clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{
CloudBackup: true,
ReplicationSpecs: []acc.ReplicationSpecRequest{
{Region: "US_EAST_2"},
},
PitEnabled: true, // you cannot copy oplogs when pit is not enabled
})
clusterName = clusterInfo.Name
terraformStr = clusterInfo.TerraformStr
clusterResourceName = clusterInfo.ResourceName
projectID = clusterInfo.ProjectID
copySettingsConfigWithRepSpecID = configCopySettings(terraformStr, projectID, clusterResourceName, false, true, &admin.DiskBackupSnapshotSchedule20240805{
ReferenceHourOfDay: conversion.Pointer(3),
ReferenceMinuteOfHour: conversion.Pointer(45),
RestoreWindowDays: conversion.Pointer(1),
})
copySettingsConfigWithZoneID = configCopySettings(terraformStr, projectID, clusterResourceName, false, false, &admin.DiskBackupSnapshotSchedule20240805{
ReferenceHourOfDay: conversion.Pointer(3),
ReferenceMinuteOfHour: conversion.Pointer(45),
RestoreWindowDays: conversion.Pointer(1),
})
checkMap = map[string]string{
"cluster_name": clusterName,
"reference_hour_of_day": "3",
"reference_minute_of_hour": "45",
"restore_window_days": "1",
"policy_item_hourly.#": "1",
"policy_item_daily.#": "1",
"policy_item_weekly.#": "1",
"policy_item_monthly.#": "1",
"policy_item_yearly.#": "1",
"policy_item_hourly.0.frequency_interval": "1",
"policy_item_hourly.0.retention_unit": "days",
"policy_item_hourly.0.retention_value": "1",
"policy_item_daily.0.frequency_interval": "1",
"policy_item_daily.0.retention_unit": "days",
"policy_item_daily.0.retention_value": "2",
"policy_item_weekly.0.frequency_interval": "4",
"policy_item_weekly.0.retention_unit": "weeks",
"policy_item_weekly.0.retention_value": "3",
"policy_item_monthly.0.frequency_interval": "5",
"policy_item_monthly.0.retention_unit": "months",
"policy_item_monthly.0.retention_value": "4",
"policy_item_yearly.0.frequency_interval": "1",
"policy_item_yearly.0.retention_unit": "years",
"policy_item_yearly.0.retention_value": "1",
}
copySettingsChecks = map[string]string{
"copy_settings.#": "1",
"copy_settings.0.cloud_provider": "AWS",
"copy_settings.0.region_name": "US_EAST_1",
"copy_settings.0.should_copy_oplogs": "true",
}
)

checksDefault := acc.AddAttrChecks(resourceName, []resource.TestCheckFunc{checkExists(resourceName)}, checkMap)
checksCreate := acc.AddAttrChecks(resourceName, checksDefault, copySettingsChecks)
checksCreateWithReplicationSpecID := acc.AddAttrSetChecks(resourceName, checksCreate, "copy_settings.0.replication_spec_id")
checksUpdateWithZoneID := acc.AddAttrSetChecks(resourceName, checksCreate, "copy_settings.0.zone_id")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { mig.PreCheckLast1XVersionSleep(t); mig.PreCheckOldPreviewEnv(t) },
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: acc.ExternalProviders(lastVersionRepSpecID),
Config: copySettingsConfigWithRepSpecID,
Check: resource.ComposeAggregateTestCheckFunc(checksCreateWithReplicationSpecID...),
},
{
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: copySettingsConfigWithZoneID,
Check: resource.ComposeAggregateTestCheckFunc(checksUpdateWithZoneID...),
},
mig.TestStepCheckEmptyPlan(copySettingsConfigWithZoneID),
},
})
}
4 changes: 3 additions & 1 deletion internal/testutil/mig/pre_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ func PreCheckBasicSleep(tb testing.TB) func() {
}
}

func PreCheckLast1XVersion(tb testing.TB) {
func PreCheckLast1XVersionSleep(tb testing.TB) {
tb.Helper()
if os.Getenv("MONGODB_ATLAS_LAST_1X_VERSION") == "" {
tb.Fatal("`MONGODB_ATLAS_LAST_1X_VERSION` must be set for this migration testing")
}
PreCheckBasic(tb)
acc.SerialSleep(tb)
}

func PreCheck(tb testing.TB) {
Expand Down