Skip to content

Commit 3313f74

Browse files
committed
Block soft_delete_enabled = false if it's already alwayson
1 parent a24f2ac commit 3313f74

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

internal/services/recoveryservices/recovery_services_vault_resource.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func resourceRecoveryServicesVaultCreate(d *pluginsdk.ResourceData, meta interfa
320320
// Only non-AlwaysOn allows update, otherwise, API will throw `BMSUserErrorSoftDeleteStateAlwaysOn` error
321321
if currentSoftDeleteState == backupresourcevaultconfigs.SoftDeleteFeatureStateAlwaysON {
322322
if !d.Get("soft_delete_enabled").(bool) {
323-
log.Printf("[WARN] Soft delete is set to AlwaysON for %s due to Azure's secure-by-default policy. Ignoring `soft_delete_enabled = false`.", id.String())
323+
return fmt.Errorf("soft delete is set to AlwaysON for %s due to Azure's secure-by-default policy. `soft_delete_enabled` cannot be set to `false`. For more information, see: https://learn.microsoft.com/en-us/azure/backup/secure-by-default", id.String())
324324
}
325325
} else {
326326
// an update on the vault will reset the vault config to default, so we handle it at last.
@@ -558,7 +558,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
558558
// Only non-AlwaysOn allows update, otherwise, API will throw `BMSUserErrorSoftDeleteStateAlwaysOn` error
559559
if currentSoftDeleteState == backupresourcevaultconfigs.SoftDeleteFeatureStateAlwaysON {
560560
if !d.Get("soft_delete_enabled").(bool) {
561-
log.Printf("[WARN] Soft delete is set to AlwaysON for %s due to Azure's secure-by-default policy. Ignoring `soft_delete_enabled = false`.", id.String())
561+
return fmt.Errorf("soft delete is set to AlwaysON for %s due to Azure's secure-by-default policy. `soft_delete_enabled` cannot be set to `false`. For more information, see: https://learn.microsoft.com/en-us/azure/backup/secure-by-default", id.String())
562562
}
563563
} else {
564564
// an update on vault will cause the vault config reset to default, so whether the config has change or not, it needs to be updated.
@@ -605,6 +605,7 @@ func resourceRecoveryServicesVaultUpdate(d *pluginsdk.ResourceData, meta interfa
605605

606606
func resourceRecoveryServicesVaultRead(d *pluginsdk.ResourceData, meta interface{}) error {
607607
client := meta.(*clients.Client).RecoveryServices.VaultsClient
608+
cfgsClient := meta.(*clients.Client).RecoveryServices.VaultsConfigsClient
608609
vaultSettingsClient := meta.(*clients.Client).RecoveryServices.VaultsSettingsClient
609610
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
610611
defer cancel()
@@ -659,10 +660,20 @@ func resourceRecoveryServicesVaultRead(d *pluginsdk.ResourceData, meta interface
659660
d.Set("storage_mode_type", string(storageModeType))
660661
}
661662

663+
cfg, err := cfgsClient.Get(ctx, cfgId)
662664
if err != nil {
663665
return fmt.Errorf("retrieving %s: %+v", cfgId, err)
664666
}
665667

668+
if !features.FivePointOh() {
669+
softDeleteEnabled := true
670+
if cfg.Model != nil && cfg.Model.Properties != nil && cfg.Model.Properties.SoftDeleteFeatureState != nil {
671+
state := *cfg.Model.Properties.SoftDeleteFeatureState
672+
softDeleteEnabled = state == backupresourcevaultconfigs.SoftDeleteFeatureStateAlwaysON || state == backupresourcevaultconfigs.SoftDeleteFeatureStateEnabled
673+
}
674+
d.Set("soft_delete_enabled", softDeleteEnabled)
675+
}
676+
666677
flattenIdentity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
667678
if err != nil {
668679
return fmt.Errorf("flattening `identity`: %+v", err)

0 commit comments

Comments
 (0)