Skip to content

Commit

Permalink
rename to protection_state
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Apr 14, 2023
1 parent 0b42299 commit ac1e49b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
26 changes: 17 additions & 9 deletions internal/services/recoveryservices/backup_protected_vm_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ func resourceRecoveryServicesBackupProtectedVMCreateUpdate(d *pluginsdk.Resource
},
}

requireAdditionalUpdate := d.Get("protection_stopped").(bool)
skipNormalUpdate := d.Get("protection_stopped").(bool) && !d.IsNewResource()
protectionState, ok := d.GetOk("protection_state")
protectionStopped := strings.EqualFold(protectionState.(string), string(backup.ProtectionStateProtectionStopped))
requireAdditionalUpdate := ok && protectionStopped
skipNormalUpdate := protectionStopped && !d.IsNewResource()

if !skipNormalUpdate {
if _, err = client.CreateOrUpdate(ctx, id.VaultName, id.ResourceGroup, id.BackupFabricName, id.ProtectionContainerName, id.Name, item); err != nil {
Expand Down Expand Up @@ -193,7 +195,7 @@ func resourceRecoveryServicesBackupProtectedVMRead(d *pluginsdk.ResourceData, me
if properties := resp.Properties; properties != nil {
if vm, ok := properties.AsAzureIaaSComputeVMProtectedItem(); ok {
d.Set("source_vm_id", vm.SourceResourceID)
d.Set("protection_stopped", vm.ProtectionState == backup.ProtectionStateProtectionStopped)
d.Set("protection_state", vm.ProtectionState)

if v := vm.PolicyID; v != nil {
d.Set("backup_policy_id", strings.Replace(*v, "Subscriptions", "subscriptions", 1))
Expand Down Expand Up @@ -421,7 +423,6 @@ func resourceRecoveryServicesBackupProtectedVMSchema() map[string]*pluginsdk.Sch
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validate.BackupPolicyID,
ExactlyOneOf: []string{"backup_policy_id", "protection_stopped"},
},

"exclude_disk_luns": {
Expand All @@ -444,11 +445,18 @@ func resourceRecoveryServicesBackupProtectedVMSchema() map[string]*pluginsdk.Sch
},
},

"protection_stopped": {
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ExactlyOneOf: []string{"backup_policy_id", "protection_stopped"},
"protection_state": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
string(backup.ProtectedItemStateIRPending),
string(backup.ProtectedItemStateProtected),
string(backup.ProtectedItemStateProtectionError),
string(backup.ProtectedItemStateProtectionStopped),
string(backup.ProtectedItemStateProtectionPaused),
string(backup.ProtectionStateInvalid),
}, false),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestAccBackupProtectedVm_protectionStopped(t *testing.T) {
},
data.ImportStep(),
{
Config: r.protectionStopped(data),
Config: r.protectionState(data, "ProtectionStopped"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("resource_group_name").Exists(),
Expand Down Expand Up @@ -361,7 +361,9 @@ resource "azurerm_virtual_machine" "test" {
enabled = true
storage_uri = azurerm_storage_account.test.primary_blob_endpoint
}
lifecycle {
ignore_changes = [tags]
}
}
resource "azurerm_recovery_services_vault" "test" {
Expand Down Expand Up @@ -717,7 +719,7 @@ resource "azurerm_backup_protected_vm" "test" {
`, r.additionalVault(data))
}

func (r BackupProtectedVmResource) protectionStopped(data acceptance.TestData) string {
func (r BackupProtectedVmResource) protectionState(data acceptance.TestData, state string) string {
return fmt.Sprintf(`
%s
Expand All @@ -726,8 +728,8 @@ resource "azurerm_backup_protected_vm" "test" {
recovery_vault_name = azurerm_recovery_services_vault.test.name
source_vm_id = azurerm_virtual_machine.test.id
include_disk_luns = [0]
protection_stopped = true
include_disk_luns = [0]
protection_state = %s
}
`, r.base(data))
`, r.base(data), state)
}
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 @@ -68,7 +68,7 @@ This allows the source vm to be deleted without having to remove the backup.

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

* `protection_stopped` - (Optional) Specifies whether to stop the protection. Defaults to `false`.
* `protection_state` - (Optional) Specifies Protection state of the backup. Possible values are `Invalid`, `IRPending`, `Protected`, `ProtectionStopped`, `ProtectionError` and `ProtectionPaused`.

## Attributes Reference

Expand Down

0 comments on commit ac1e49b

Please sign in to comment.