Skip to content

Commit

Permalink
update backup_policy_id to Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Feb 22, 2023
1 parent 88fbbdb commit ce5343e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func resourceRecoveryServicesBackupProtectedVMCreateUpdate(d *pluginsdk.Resource
},
}

requireAdditionalupdate := false
requireAdditionalUpdate := false
if d.Get("protection_stopped").(bool) && d.IsNewResource() { // it only needs an additional update for new resource.
requireAdditionalupdate = true
requireAdditionalUpdate = true
}

if _, err = client.CreateOrUpdate(ctx, vaultName, resourceGroup, "Azure", containerName, protectedItemName, item); err != nil {
Expand All @@ -120,7 +120,7 @@ func resourceRecoveryServicesBackupProtectedVMCreateUpdate(d *pluginsdk.Resource
return err
}

if requireAdditionalupdate {
if requireAdditionalUpdate {
updateInput := backup.ProtectedItemResource{
Properties: &backup.AzureIaaSComputeVMProtectedItem{
ProtectionState: backup.ProtectionStateProtectionStopped,
Expand Down Expand Up @@ -405,8 +405,9 @@ func resourceRecoveryServicesBackupProtectedVMSchema() map[string]*pluginsdk.Sch

"backup_policy_id": {
Type: pluginsdk.TypeString,
Required: true,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
ExactlyOneOf: []string{"backup_policy_id", "protection_stopped"},
},

"exclude_disk_luns": {
Expand All @@ -430,9 +431,10 @@ func resourceRecoveryServicesBackupProtectedVMSchema() map[string]*pluginsdk.Sch
},

"protection_stopped": {
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"backup_policy_id", "protection_stopped"},
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ func TestAccBackupProtectedVm_protectionStopped(t *testing.T) {
r := BackupProtectedVmResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("resource_group_name").Exists(),
),
},
data.ImportStep(),
{
Config: r.protectionStopped(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down Expand Up @@ -716,7 +724,6 @@ resource "azurerm_backup_protected_vm" "test" {
resource_group_name = azurerm_resource_group.test.name
recovery_vault_name = azurerm_recovery_services_vault.test.name
source_vm_id = azurerm_virtual_machine.test.id
backup_policy_id = azurerm_backup_policy_vm.test.id
include_disk_luns = [0]
protection_stopped = true
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/backup_protected_vm.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following arguments are supported:
~> **NOTE:** After creation, the `source_vm_id` property can be removed without forcing a new resource to be created; however, setting it to a different ID will create a new resource.
This allows the source vm to be deleted without having to remove the backup.

* `backup_policy_id` - (Required) Specifies the id of the backup policy to use.
* `backup_policy_id` - (Optional) Specifies the id of the backup policy to use. Required when `protection_stopped` is not specified.

* `exclude_disk_luns` - (Optional) A list of Disks' Logical Unit Numbers(LUN) to be excluded for VM Protection.

Expand Down

0 comments on commit ce5343e

Please sign in to comment.