diff --git a/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time-advance-cluster/main.tf b/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time-advance-cluster/main.tf index 153c6eb256..83476a6d0a 100644 --- a/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time-advance-cluster/main.tf +++ b/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time-advance-cluster/main.tf @@ -41,7 +41,7 @@ resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { count = (var.point_in_time_utc_seconds == 0 ? 0 : 1) project_id = mongodbatlas_cloud_backup_snapshot.test.project_id cluster_name = mongodbatlas_cloud_backup_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id + snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id # for provider versions > 1.15.1 the snapshot_id field can be omitted when delivery_type_config is "point_in_time" delivery_type_config { point_in_time = true diff --git a/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time/main.tf b/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time/main.tf index 5c9e19a0d2..7c518367ed 100644 --- a/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time/main.tf +++ b/examples/mongodbatlas_cloud_provider_snapshot_restore_job/point-in-time/main.tf @@ -30,7 +30,7 @@ resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { count = (var.point_in_time_utc_seconds == 0 ? 0 : 1) project_id = mongodbatlas_cloud_backup_snapshot.test.project_id cluster_name = mongodbatlas_cloud_backup_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id + snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id # for provider versions > 1.15.1 the snapshot_id field can be omitted when delivery_type_config is "point_in_time" delivery_type_config { point_in_time = true diff --git a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go index 9bdc9268e4..21d35e7b84 100644 --- a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go +++ b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go @@ -37,7 +37,7 @@ func Resource() *schema.Resource { }, "snapshot_id": { Type: schema.TypeString, - Required: true, + Optional: true, ForceNew: true, }, "delivery_type_config": { diff --git a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go index b44b29a0db..41777ed783 100644 --- a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go +++ b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job_test.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "os" + "regexp" "testing" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -68,6 +69,7 @@ func TestAccBackupRSCloudBackupSnapshotRestoreJob_basicDownload(t *testing.T) { clusterName = fmt.Sprintf("test-acc-%s", acctest.RandString(10)) description = fmt.Sprintf("My description in %s", clusterName) retentionInDays = "1" + useSnapshotID = true ) resource.ParallelTest(t, resource.TestCase{ @@ -76,13 +78,17 @@ func TestAccBackupRSCloudBackupSnapshotRestoreJob_basicDownload(t *testing.T) { CheckDestroy: testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobDestroy, Steps: []resource.TestStep{ { - Config: testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigDownload(orgID, projectName, clusterName, description, retentionInDays), + Config: testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigDownload(orgID, projectName, clusterName, description, retentionInDays, useSnapshotID), Check: resource.ComposeTestCheckFunc( testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobExists(resourceName, &cloudBackupSnapshotRestoreJob), testAccCheckMongoDBAtlasCloudBackupSnapshotRestoreJobAttributes(&cloudBackupSnapshotRestoreJob, "download"), resource.TestCheckResourceAttr(resourceName, "delivery_type_config.0.download", "true"), ), }, + { + Config: testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigDownload(orgID, projectName, clusterName, description, retentionInDays, !useSnapshotID), + ExpectError: regexp.MustCompile("SNAPSHOT_NOT_FOUND"), + }, }, }) } @@ -246,7 +252,12 @@ data "mongodbatlas_cloud_backup_snapshot_restore_jobs" "pagination" { `, orgID, projectName, clusterName, description, retentionInDays, targetProjectName, targetClusterName) } -func testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigDownload(orgID, projectName, clusterName, description, retentionInDays string) string { +func testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigDownload(orgID, projectName, clusterName, description, retentionInDays string, useSnapshotID bool) string { + var snapshotIDField string + if useSnapshotID { + snapshotIDField = `snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id` + } + return fmt.Sprintf(` resource "mongodbatlas_project" "backup_project" { name = %[2]q @@ -272,13 +283,13 @@ resource "mongodbatlas_cloud_backup_snapshot" "test" { resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_backup_snapshot.test.project_id cluster_name = mongodbatlas_cloud_backup_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id + %[6]s delivery_type_config { download = true } } - `, orgID, projectName, clusterName, description, retentionInDays) + `, orgID, projectName, clusterName, description, retentionInDays, snapshotIDField) } func testAccMongoDBAtlasCloudBackupSnapshotRestoreJobConfigPointInTime(orgID, projectName, clusterName, description, retentionInDays, targetProjectName string, pointTimeUTC int64) string { @@ -328,7 +339,6 @@ resource "mongodbatlas_cloud_backup_snapshot" "test" { resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { project_id = mongodbatlas_cloud_backup_snapshot.test.project_id cluster_name = mongodbatlas_cloud_backup_snapshot.test.cluster_name - snapshot_id = mongodbatlas_cloud_backup_snapshot.test.id delivery_type_config { point_in_time = true diff --git a/website/docs/r/cloud_backup_snapshot_restore_job.html.markdown b/website/docs/r/cloud_backup_snapshot_restore_job.html.markdown index 1df76acded..2571213696 100644 --- a/website/docs/r/cloud_backup_snapshot_restore_job.html.markdown +++ b/website/docs/r/cloud_backup_snapshot_restore_job.html.markdown @@ -134,7 +134,6 @@ resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { * `project_id` - (Required) The unique identifier of the project for the Atlas cluster whose snapshot you want to restore. * `cluster_name` - (Required) The name of the Atlas cluster whose snapshot you want to restore. -* `snapshot_id` - (Required) Unique identifier of the snapshot to restore. * `delivery_type_config` - (Required) Type of restore job to create. Possible configurations are: **download**, **automated**, or **pointInTime** only one must be set it in ``true``. * `delivery_type_config.automated` - Set to `true` to use the automated configuration. * `delivery_type_config.download` - Set to `true` to use the download configuration. @@ -144,6 +143,7 @@ resource "mongodbatlas_cloud_backup_snapshot_restore_job" "test" { * `delivery_type_config.oplog_ts` - Optional setting for **pointInTime** configuration. Timestamp in the number of seconds that have elapsed since the UNIX epoch from which to you want to restore this snapshot. This is the first part of an Oplog timestamp. * `delivery_type_config.oplog_inc` - Optional setting for **pointInTime** configuration. Oplog operation number from which to you want to restore this snapshot. This is the second part of an Oplog timestamp. Used in conjunction with `oplog_ts`. * `delivery_type_config.point_in_time_utc_seconds` - Optional setting for **pointInTime** configuration. Timestamp in the number of seconds that have elapsed since the UNIX epoch from which you want to restore this snapshot. Used instead of oplog settings. +* `snapshot_id` - Optional setting for **pointInTime** configuration. Unique identifier of the snapshot to restore. ### Download Atlas provides a URL to download a .tar.gz of the snapshot with snapshotId.