Skip to content

Commit 6e2d03d

Browse files
raazanandmelinath
authored andcommitted
Immutable backups (GoogleCloudPlatform#14080)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]>
1 parent 2b61344 commit 6e2d03d

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed

mmv1/products/netapp/BackupVault.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,29 @@ properties:
116116
description: |
117117
Name of the Backup vault created in backup region.
118118
output: true
119+
- name: 'backupRetentionPolicy'
120+
type: NestedObject
121+
description: |
122+
Backup retention policy defining the retention of the backups.
123+
properties:
124+
- name: 'backupMinimumEnforcedRetentionDays'
125+
type: Integer
126+
description: |
127+
Minimum retention duration in days for backups in the backup vault.
128+
required: true
129+
- name: 'dailyBackupImmutable'
130+
type: Boolean
131+
description: |
132+
Indicates if the daily backups are immutable. At least one of daily_backup_immutable, weekly_backup_immutable, monthly_backup_immutable and manual_backup_immutable must be true.
133+
- name: 'weeklyBackupImmutable'
134+
type: Boolean
135+
description: |
136+
Indicates if the weekly backups are immutable. At least one of daily_backup_immutable, weekly_backup_immutable, monthly_backup_immutable and manual_backup_immutable must be true.
137+
- name: 'monthlyBackupImmutable'
138+
type: Boolean
139+
description: |
140+
Indicates if the monthly backups are immutable. At least one of daily_backup_immutable, weekly_backup_immutable, monthly_backup_immutable and manual_backup_immutable must be true.
141+
- name: 'manualBackupImmutable'
142+
type: Boolean
143+
description: |
144+
Indicates if the manual backups are immutable. At least one of daily_backup_immutable, weekly_backup_immutable, monthly_backup_immutable and manual_backup_immutable must be true.

mmv1/third_party/terraform/services/netapp/resource_netapp_backup_test.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,173 @@ resource "google_netapp_backup" "test_backup" {
325325
}
326326
`, context)
327327
}
328+
329+
func TestAccNetappBackup_NetappImmutableBackup(t *testing.T) {
330+
context := map[string]interface{}{
331+
"network_name": acctest.BootstrapSharedServiceNetworkingConnection(t, "gcnv-network-config-3", acctest.ServiceNetworkWithParentService("netapp.servicenetworking.goog")),
332+
"random_suffix": acctest.RandString(t, 10),
333+
}
334+
335+
acctest.VcrTest(t, resource.TestCase{
336+
PreCheck: func() { acctest.AccTestPreCheck(t) },
337+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
338+
CheckDestroy: testAccCheckNetappBackupDestroyProducer(t),
339+
ExternalProviders: map[string]resource.ExternalProvider{
340+
"time": {},
341+
},
342+
Steps: []resource.TestStep{
343+
{
344+
Config: testAccNetappBackup_ImmutableBackup(context),
345+
},
346+
{
347+
ResourceName: "google_netapp_backup.test_backup",
348+
ImportState: true,
349+
ImportStateVerify: true,
350+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "vault_name"},
351+
},
352+
{
353+
Config: testAccNetappBackup_ImmutableBackupUpdate(context),
354+
},
355+
{
356+
ResourceName: "google_netapp_backup.test_backup",
357+
ImportState: true,
358+
ImportStateVerify: true,
359+
ImportStateVerifyIgnore: []string{"labels", "location", "name", "terraform_labels", "vault_name"},
360+
},
361+
},
362+
})
363+
}
364+
365+
func testAccNetappBackup_ImmutableBackup(context map[string]interface{}) string {
366+
return acctest.Nprintf(`
367+
data "google_compute_network" "default" {
368+
name = "%{network_name}"
369+
}
370+
resource "google_netapp_storage_pool" "default" {
371+
name = "tf-test-backup-pool%{random_suffix}"
372+
location = "us-central1"
373+
service_level = "FLEX"
374+
capacity_gib = "2048"
375+
network = data.google_compute_network.default.id
376+
zone = "us-central1-a"
377+
replica_zone = "us-central1-b"
378+
}
379+
resource "time_sleep" "wait_3_minutes" {
380+
depends_on = [google_netapp_storage_pool.default]
381+
create_duration = "3m"
382+
}
383+
resource "google_netapp_volume" "default" {
384+
name = "tf-test-backup-volume%{random_suffix}"
385+
location = "us-central1"
386+
capacity_gib = "100"
387+
share_name = "tf-test-backup-volume%{random_suffix}"
388+
storage_pool = google_netapp_storage_pool.default.name
389+
protocols = ["NFSV3"]
390+
deletion_policy = "FORCE"
391+
backup_config {
392+
backup_vault = google_netapp_backup_vault.default.id
393+
}
394+
}
395+
resource "google_netapp_backup_vault" "default" {
396+
name = "tf-test-backup-vault%{random_suffix}"
397+
location = "us-central1"
398+
backup_retention_policy {
399+
backup_minimum_enforced_retention_days = 2
400+
daily_backup_immutable = true
401+
weekly_backup_immutable = false
402+
monthly_backup_immutable = false
403+
manual_backup_immutable = false
404+
}
405+
}
406+
resource "google_netapp_volume_snapshot" "default" {
407+
depends_on = [google_netapp_volume.default]
408+
location = "us-central1"
409+
volume_name = google_netapp_volume.default.name
410+
description = "This is a test description"
411+
name = "testvolumesnap%{random_suffix}"
412+
labels = {
413+
key= "test"
414+
value= "snapshot"
415+
}
416+
}
417+
resource "google_netapp_backup" "test_backup" {
418+
name = "tf-test-test-backup%{random_suffix}"
419+
description = "This is a test immutable backup"
420+
source_volume = google_netapp_volume.default.id
421+
location = "us-central1"
422+
vault_name = google_netapp_backup_vault.default.name
423+
source_snapshot = google_netapp_volume_snapshot.default.id
424+
labels = {
425+
key= "test"
426+
value= "backup"
427+
}
428+
}
429+
`, context)
430+
}
431+
432+
func testAccNetappBackup_ImmutableBackupUpdate(context map[string]interface{}) string {
433+
return acctest.Nprintf(`
434+
data "google_compute_network" "default" {
435+
name = "%{network_name}"
436+
}
437+
resource "google_netapp_storage_pool" "default" {
438+
name = "tf-test-backup-pool%{random_suffix}"
439+
location = "us-central1"
440+
service_level = "FLEX"
441+
capacity_gib = "2048"
442+
network = data.google_compute_network.default.id
443+
zone = "us-central1-a"
444+
replica_zone = "us-central1-b"
445+
}
446+
resource "time_sleep" "wait_3_minutes" {
447+
depends_on = [google_netapp_storage_pool.default]
448+
create_duration = "3m"
449+
}
450+
resource "google_netapp_volume" "default" {
451+
name = "tf-test-backup-volume%{random_suffix}"
452+
location = "us-central1"
453+
capacity_gib = "100"
454+
share_name = "tf-test-backup-volume%{random_suffix}"
455+
storage_pool = google_netapp_storage_pool.default.name
456+
protocols = ["NFSV3"]
457+
deletion_policy = "FORCE"
458+
backup_config {
459+
backup_vault = google_netapp_backup_vault.default.id
460+
}
461+
}
462+
resource "google_netapp_backup_vault" "default" {
463+
name = "tf-test-backup-vault%{random_suffix}"
464+
location = "us-central1"
465+
backup_retention_policy {
466+
backup_minimum_enforced_retention_days = 12
467+
daily_backup_immutable = true
468+
weekly_backup_immutable = true
469+
monthly_backup_immutable = true
470+
manual_backup_immutable = true
471+
}
472+
}
473+
resource "google_netapp_volume_snapshot" "default" {
474+
depends_on = [google_netapp_volume.default]
475+
location = "us-central1"
476+
volume_name = google_netapp_volume.default.name
477+
description = "This is a test description"
478+
name = "testvolumesnap%{random_suffix}"
479+
labels = {
480+
key= "test"
481+
value= "snapshot"
482+
}
483+
}
484+
resource "google_netapp_backup" "test_backup" {
485+
name = "tf-test-test-backup%{random_suffix}"
486+
description = "This is a test immutable backup"
487+
source_volume = google_netapp_volume.default.id
488+
location = "us-central1"
489+
vault_name = google_netapp_backup_vault.default.name
490+
source_snapshot = google_netapp_volume_snapshot.default.id
491+
labels = {
492+
key= "test"
493+
value= "backup"
494+
}
495+
}
496+
`, context)
497+
}

0 commit comments

Comments
 (0)