Skip to content

Commit

Permalink
fix: Converts snapshot_id field from required to optional. (#1924)
Browse files Browse the repository at this point in the history
* fix: Converts snapshot_id field from required to optional.

* updates examples and tests.

* updates example format.

* fixes test format.

* fixes test format.

* fixes test format.

* fixes test format.

* Update website/docs/r/cloud_backup_snapshot_restore_job.html.markdown

Co-authored-by: Oriol <oriol.abadal@mongodb.com>

---------

Co-authored-by: Oriol <oriol.abadal@mongodb.com>
  • Loading branch information
marcosuma and oarbusi committed Feb 15, 2024
1 parent 090a04e commit 8952761
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -37,7 +37,7 @@ func Resource() *schema.Resource {
},
"snapshot_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
},
"delivery_type_config": {
Expand Down
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
Expand Down Expand Up @@ -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{
Expand All @@ -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"),
},
},
})
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 8952761

Please sign in to comment.