Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_data_protection_backup_vault : support soft_delete and retention_duration_in_days properties #24775

Merged
merged 5 commits into from
Feb 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package dataprotection

import (
"context"
"fmt"
"log"
"regexp"
Expand Down Expand Up @@ -72,8 +73,28 @@ func resourceDataProtectionBackupVault() *pluginsdk.Resource {

"identity": commonschema.SystemAssignedIdentityOptional(),

"retention_duration_in_days": {
Type: pluginsdk.TypeFloat,
Optional: true,
Default: 14,
ValidateFunc: validation.FloatBetween(14, 180),
},

"soft_delete": {
Type: pluginsdk.TypeString,
Optional: true,
Default: backupvaults.SoftDeleteStateOn,
ValidateFunc: validation.StringInSlice(backupvaults.PossibleValuesForSoftDeleteState(), false),
},

"tags": tags.Schema(),
},

CustomizeDiff: pluginsdk.CustomDiffWithAll(
pluginsdk.ForceNewIfChange("soft_delete", func(ctx context.Context, old, new, meta interface{}) bool {
return old.(string) == string(backupvaults.SoftDeleteStateAlwaysOn) && new.(string) != string(backupvaults.SoftDeleteStateAlwaysOn)
}),
),
}

// Confirmed with the service team that `SnapshotStore` has been replaced with `OperationalStore`.
Expand Down Expand Up @@ -144,10 +165,20 @@ func resourceDataProtectionBackupVaultCreateUpdate(d *pluginsdk.ResourceData, me
Type: &storageSettingType,
},
},
SecuritySettings: &backupvaults.SecuritySettings{
SoftDeleteSettings: &backupvaults.SoftDeleteSettings{
State: pointer.To(backupvaults.SoftDeleteState(d.Get("soft_delete").(string))),
},
},
},
Identity: expandedIdentity,
Tags: expandTags(d.Get("tags").(map[string]interface{})),
}

if v, ok := d.GetOk("retention_duration_in_days"); ok {
parameters.Properties.SecuritySettings.SoftDeleteSettings.RetentionDurationInDays = pointer.To(v.(float64))
}

err = client.CreateOrUpdateThenPoll(ctx, id, parameters)
if err != nil {
return fmt.Errorf("creating DataProtection BackupVault (%q): %+v", id, err)
Expand Down Expand Up @@ -186,6 +217,12 @@ func resourceDataProtectionBackupVaultRead(d *pluginsdk.ResourceData, meta inter
d.Set("datastore_type", string(pointer.From((props.StorageSettings)[0].DatastoreType)))
d.Set("redundancy", string(pointer.From((props.StorageSettings)[0].Type)))
}
if securitySetting := model.Properties.SecuritySettings; securitySetting != nil {
if softDelete := securitySetting.SoftDeleteSettings; softDelete != nil {
d.Set("soft_delete", string(pointer.From(softDelete.State)))
d.Set("retention_duration_in_days", pointer.From(softDelete.RetentionDurationInDays))
}
}

if err = d.Set("identity", flattenBackupVaultDppIdentityDetails(model.Identity)); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ func TestAccDataProtectionBackupVault_update(t *testing.T) {
),
},
data.ImportStep(),
{
Config: r.completeUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down Expand Up @@ -200,7 +207,31 @@ resource "azurerm_data_protection_backup_vault" "test" {
identity {
type = "SystemAssigned"
}
soft_delete = "Off"
retention_duration_in_days = 14
tags = {
ENV = "Test"
}
}
`, template, data.RandomInteger)
}

func (r DataProtectionBackupVaultResource) completeUpdate(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
%s

resource "azurerm_data_protection_backup_vault" "test" {
name = "acctest-bv-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
datastore_type = "VaultStore"
redundancy = "LocallyRedundant"
identity {
type = "SystemAssigned"
}
soft_delete = "On"
retention_duration_in_days = 15
tags = {
ENV = "Test"
}
Expand All @@ -219,7 +250,6 @@ resource "azurerm_data_protection_backup_vault" "test" {
location = azurerm_resource_group.test.location
datastore_type = "VaultStore"
redundancy = "LocallyRedundant"

tags = {
ENV = "Test"
}
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/data_protection_backup_vault.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ The following arguments are supported:

* `identity` - (Optional) An `identity` block as defined below.

* `retention_duration_in_days` - (Optional) The soft delete retention duration for this Backup Vault. Possible values are between `14` and `180`. Defaults to `14`.

-> **Note:** The `retention_duration_in_days` is the number of days for which deleted data is retained before being permanently deleted. Retention period till 14 days are free of cost, however, retention beyond 14 days may incur additional charges. The `retention_duration_in_days` is required when the `soft_delete` is set to `On`.

* `soft_delete` - (Optional) The state of soft delete for this Backup Vault. Possible values are `AlwaysOn`, `Off` and `On`. Defaults to `On`.

-> **Note:** Once the `soft_delete` is set to `AlwaysOn`, the setting cannot be changed.

* `tags` - (Optional) A mapping of tags which should be assigned to the Backup Vault.

---
Expand Down
Loading