Repository: ansible-collections/azure
Pull request #1887: add enhanced backup policy to azure_rm_backuppolicy
Author: login: Klaas-
Labels: name: question
description: Further information is requested
name: ready-for-review
description: The PR is ready to be reviewed and merged.
name: medium-priority
description: Medium priority
Created: 2025-04-08T12:10:22Z | Merged: 2025-04-16T08:46:42Z

##### SUMMARY
<!--- Describe the change below, including rationale and design decisions -->
add enhanced backup policy to azure_rm_backuppolicy
I have only added daily schedules for now.
I have also noticed that the module is not idempotent, but it was not before my change either, will create a follow up issue for that.

Fixes #1886 
<!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
- Feature Pull Request

##### COMPONENT NAME
<!--- Write the short name of the module, plugin, task or feature below -->
azure_rm_backuppolicy



Linked issue #1886: azure_rm_backuppolicy - support enhanced backup policies
<!--- Verify first that your feature was not already discussed on GitHub -->
<!--- Complete *all* sections as described, this form is processed automatically -->

##### SUMMARY
azure_rm_backuppolicy currently does not support enhanced backup policies, I'll create a PR to start daily schedules

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
azure_rm_backuppolicy

##### ADDITIONAL INFORMATION
<!--- Describe how the feature would be used, why it is needed and what it would solve -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
azure.azcollection.azure_rm_backuppolicy:
  subscription_id: "{{ subscription_id }}"
  vault_name: "{{ vault_name }}"
  resource_group: "{{ resource_group_name }}"
  backup_policy_type: V2
  name: "{{ backup_policy_name }}"
  state: present
  backup_management_type: AzureIaasVM
  schedule_run_frequency: Daily
  instant_recovery_snapshot_retention: 7
  daily_retention_count: 28
  time_zone: UTC
  schedule_run_time: 20
```

<!--- HINT: You can also paste gist.github.com links for larger files -->


Diff:
diff --git a/plugins/modules/azure_rm_backuppolicy.py b/plugins/modules/azure_rm_backuppolicy.py
index 6155ca0b73..74e04884fd 100644
--- a/plugins/modules/azure_rm_backuppolicy.py
+++ b/plugins/modules/azure_rm_backuppolicy.py
@@ -52,6 +52,14 @@
         choices:
             - AzureIaasVM
         type: str
+    policy_type:
+        description:
+            - Defines the type of backup policy
+        default: V1
+        choices:
+            - V1
+            - V2
+        type: str
     schedule_run_time:
         description:
             - The hour to run backups.
@@ -139,6 +147,20 @@
       - "Friday"
     time_zone: "Pacific Standard Time"
     schedule_run_time: 8
+
+- name: Create daily enhanced policy
+  azure.azcollection.azure_rm_backuppolicy:
+    vault_name: Vault_Name
+    name: Policy_Name_Enhanced
+    resource_group: Resource_Group_Name
+    policy_type: V2
+    state: present
+    backup_management_type: AzureIaasVM
+    schedule_run_frequency: Daily
+    instant_recovery_snapshot_retention: 7
+    daily_retention_count: 28
+    time_zone: UTC
+    schedule_run_time: 20
 '''
 
 RETURN = '''
@@ -231,6 +253,7 @@ def __init__(self):
             resource_group=dict(type='str', required=True),
             state=dict(type='str', default='present', choices=['present', 'absent']),
             backup_management_type=dict(type='str', choices=['AzureIaasVM']),
+            policy_type=dict(type='str', default='V1', choices=['V1', 'V2']),
             schedule_run_time=dict(type='int'),
             instant_recovery_snapshot_retention=dict(type='int'),
             schedule_run_frequency=dict(type='str', choices=['Daily', 'Weekly']),
@@ -245,6 +268,7 @@ def __init__(self):
         self.name = None
         self.resource_group = None
         self.backup_management_type = None
+        self.policy_type = None
         self.schedule_run_time = None
         self.instant_recovery_snapshot_retention = None
         self.schedule_run_frequency = None
@@ -408,10 +432,15 @@ def create_or_update_backup_policy(self):
                 self.fail(e)
 
             # create a schedule policy based on schedule_run_frequency
-            schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicy(schedule_run_frequency=self.schedule_run_frequency,
-                                                                                        schedule_run_days=self.schedule_days,
-                                                                                        schedule_run_times=schedule_run_times_as_datetimes,
-                                                                                        schedule_weekly_frequency=self.schedule_weekly_frequency)
+            if self.policy_type == 'V1':
+                schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicy(schedule_run_frequency=self.schedule_run_frequency,
+                                                                                            schedule_run_days=self.schedule_days,
+                                                                                            schedule_run_times=schedule_run_times_as_datetimes,
+                                                                                            schedule_weekly_frequency=self.schedule_weekly_frequency)
+            elif self.policy_type == 'V2':
+                schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicyV2(
+                    schedule_run_frequency=self.schedule_run_frequency, daily_schedule=self.recovery_services_backup_models.WeeklySchedule(
+                        schedule_run_days=self.schedule_days, schedule_run_times=schedule_run_times_as_datetimes))
 
             daily_retention_schedule = None
             weekly_retention_schedule = None
@@ -441,7 +470,8 @@ def create_or_update_backup_policy(self):
                                                                 schedule_policy=schedule_policy,
                                                                 retention_policy=retention_policy,
                                                                 instant_rp_retention_range_in_days=self.instant_recovery_snapshot_retention,
-                                                                time_zone=self.time_zone)
+                                                                time_zone=self.time_zone,
+                                                                policy_type=self.policy_type)
 
             if policy_definition:
                 policy_resource = self.recovery_services_backup_models.ProtectionPolicyResource(properties=policy_definition)
diff --git a/tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml b/tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
index 4d0a3bdbbb..f1e943545f 100644
--- a/tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
+++ b/tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
@@ -1,19 +1,21 @@
+---
 - name: Set Facts for Tests
   ansible.builtin.set_fact:
     vault_name: "rsv{{ resource_group | hash('md5') | truncate(22, True, '') }}"
     location: "eastus"
     policy_name_daily: "bp-daily-policy-{{ resource_group | hash('md5') | truncate(22, True, '') }}"
+    policy_name_daily_enhanced: "bp-daily-policy-{{ resource_group | hash('md5') | truncate(22, True, '') }}-enhanced"
     policy_name_weekly: "bp-weekly-policy-{{ resource_group | hash('md5') | truncate(22, True, '') }}"
 
 - name: Create Azure Recovery Service vault
-  azure_rm_recoveryservicesvault:
+  azure.azcollection.azure_rm_recoveryservicesvault:
     resource_group: "{{ resource_group }}"
     name: "{{ vault_name }}"
     location: "{{ location }}"
     state: "present"
 
 - name: Create a daily VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_daily }}"
     resource_group: "{{ resource_group }}"
@@ -27,7 +29,7 @@
   register: daily_policy_output
 
 - name: Create a daily VM backup policy
-  azure_rm_backuppolicy_info:
+  azure.azcollection.azure_rm_backuppolicy_info:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_daily }}"
     resource_group: "{{ resource_group }}"
@@ -60,13 +62,50 @@
     time_zone: "Pacific Standard Time"
     schedule_run_time: 14
   register: daily_policy_output_idempotent
+
 - name: Assert that there is no change after second deletion of daily backup policy
   ansible.builtin.assert:
     that:
       - not daily_policy_output_idempotent.changed
 
+- name: Create a daily enhanced VM backup policy
+  azure.azcollection.azure_rm_backuppolicy:
+    vault_name: "{{ vault_name }}"
+    name: "{{ policy_name_daily_enhanced }}"
+    resource_group: "{{ resource_group }}"
+    policy_type: V2
+    state: present
+    backup_management_type: "AzureIaasVM"
+    schedule_run_frequency: "Daily"
+    instant_recovery_snapshot_retention: 7
+    daily_retention_count: 12
+    time_zone: "Pacific Standard Time"
+    schedule_run_time: 14
+  register: daily_policy_output_enhanced
+
+- name: Create a daily VM backup policy
+  azure.azcollection.azure_rm_backuppolicy_info:
+    vault_name: "{{ vault_name }}"
+    name: "{{ policy_name_daily_enhanced }}"
+    resource_group: "{{ resource_group }}"
+  register: backup_policy_exists_enhanced
+
+- name: Assert success on daily backup policy creation
+  ansible.builtin.assert:
+    that:
+      - daily_policy_output_enhanced.changed
+      - daily_policy_output_enhanced.name == policy_name_daily_enhanced
+
+- name: Assert Policy Success Retrieving Info
+  ansible.builtin.assert:
+    that:
+      - backup_policy_exists_enhanced.id == daily_policy_output_enhanced.id
+      - backup_policy_exists_enhanced.location == daily_policy_output_enhanced.location
+      - backup_policy_exists_enhanced.name == daily_policy_output_enhanced.name
+      - backup_policy_exists_enhanced.type == daily_policy_output_enhanced.type
+
 - name: Update daily VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_daily }}"
     resource_group: "{{ resource_group }}"
@@ -86,7 +125,7 @@
       - daily_policy_output_update.name == policy_name_daily
 
 - name: Create a weekly VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_weekly }}"
     resource_group: "{{ resource_group }}"
@@ -110,7 +149,7 @@
       - weekly_policy_output.name == policy_name_weekly
 
 - name: Update weekly VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_weekly }}"
     resource_group: "{{ resource_group }}"
@@ -134,7 +173,7 @@
       - weekly_policy_output_update.name == policy_name_weekly
 
 - name: Delete a daily VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_daily }}"
     resource_group: "{{ resource_group }}"
@@ -146,8 +185,21 @@
     that:
       - daily_policy_output_delete.changed
 
+- name: Delete a daily VM enhanced backup policy
+  azure.azcollection.azure_rm_backuppolicy:
+    vault_name: "{{ vault_name }}"
+    name: "{{ policy_name_daily_enhanced }}"
+    resource_group: "{{ resource_group }}"
+    state: absent
+  register: daily_policy_output_enhanced_delete
+
+- name: Assert success on daily enhanced backup policy deletion
+  ansible.builtin.assert:
+    that:
+      - daily_policy_output_enhanced_delete.changed
+
 - name: Delete a weekly VM backup policy
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_weekly }}"
     resource_group: "{{ resource_group }}"
@@ -160,7 +212,7 @@
       - weekly_policy_output_delete.changed
 
 - name: Delete a daily VM backup policy (idempotent)
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_daily }}"
     resource_group: "{{ resource_group }}"
@@ -172,8 +224,21 @@
     that:
       - not daily_policy_output_delete_idempotent.changed
 
+- name: Delete a daily VM enhanced backup policy (idempotent)
+  azure.azcollection.azure_rm_backuppolicy:
+    vault_name: "{{ vault_name }}"
+    name: "{{ policy_name_daily_enhanced }}"
+    resource_group: "{{ resource_group }}"
+    state: absent
+  register: daily_policy_output_enhanced_delete_idempotent
+
+- name: Assert that there is no change after second deletion of daily enhanced backup policy
+  ansible.builtin.assert:
+    that:
+      - not daily_policy_output_enhanced_delete_idempotent.changed
+
 - name: Delete a weekly VM backup policy (idempotent)
-  azure_rm_backuppolicy:
+  azure.azcollection.azure_rm_backuppolicy:
     vault_name: "{{ vault_name }}"
     name: "{{ policy_name_weekly }}"
     resource_group: "{{ resource_group }}"


Reviews:
user: login: Fred-sun
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T06:36:53Z
user: login: Fred-sun
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T06:38:14Z
user: login: Fred-sun
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T16:01:02Z
user: login: Fred-sun
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-09T16:20:20Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:58:03Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:58:26Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:58:47Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:58:51Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:58:57Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:59:23Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:59:28Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-10T06:59:33Z
user: login: Fred-sun
body: last change request!
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-04-14T08:51:09Z
user: login: Klaas-
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-14T08:56:13Z
user: login: xuzhang3
state: DISMISSED
author_association: COLLABORATOR
submitted_at: 2025-04-16T06:37:05Z

Review comments:
diff_hunk: @@ -455,3 +484,4 @@ def main():
 
 if __name__ == '__main__':
     main()
+
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: Trailing newlines
```suggestion
```
created_at: 2025-04-09T06:33:57Z
author_association: COLLABORATOR
diff_hunk: @@ -189,6 +211,7 @@ def __init__(self):
             resource_group=dict(type='str', required=True),
             state=dict(type='str', default='present', choices=['present', 'absent']),
             backup_management_type=dict(type='str', choices=['AzureIaasVM']),
+            backup_policy_type=dict(type='str', default='V1', choices=['V1','V2']),
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: ```suggestion
            backup_policy_type=dict(type='str', default='V1', choices=['V1', 'V2']),
```
created_at: 2025-04-09T06:34:51Z
author_association: COLLABORATOR
diff_hunk: @@ -340,10 +364,14 @@ def create_or_update_backup_policy(self):
                 self.fail(e)
 
             # create a schedule policy based on schedule_run_frequency
-            schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicy(schedule_run_frequency=self.schedule_run_frequency,
-                                                                                        schedule_run_days=self.schedule_days,
-                                                                                        schedule_run_times=schedule_run_times_as_datetimes,
-                                                                                        schedule_weekly_frequency=self.schedule_weekly_frequency)
+            if self.backup_policy_type == 'V1':
+                schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicy(schedule_run_frequency=self.schedule_run_frequency,
+                                                                                            schedule_run_days=self.schedule_days,
+                                                                                            schedule_run_times=schedule_run_times_as_datetimes,
+                                                                                            schedule_weekly_frequency=self.schedule_weekly_frequency)
+            elif self.backup_policy_type == 'V2':
+                schedule_policy = self.recovery_services_backup_models.SimpleSchedulePolicyV2(schedule_run_frequency=self.schedule_run_frequency,
+                                                                                              daily_schedule=self.recovery_services_backup_models.WeeklySchedule(schedule_run_days=self.schedule_days, schedule_run_times=schedule_run_times_as_datetimes))
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body:  line too long
created_at: 2025-04-09T06:35:16Z
author_association: COLLABORATOR
diff_hunk: @@ -52,6 +52,14 @@
         choices:
             - AzureIaasVM
         type: str
+    backup_policy_type:
+        description:
+            - Defines the type of backup policy
+        default: V2
+        choices:
+            - V1
+            - V2
+        type: str
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: Not match with argument
```suggestion
        type: str
        default: V1
```
created_at: 2025-04-09T06:38:11Z
author_association: COLLABORATOR
diff_hunk: @@ -166,3 +230,4 @@
   ansible.builtin.assert:
     that:
       - not weekly_policy_output_delete_idempotent.changed
+
path: tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
user: login: Fred-sun
body: Too many blank lines
```suggestion
```
created_at: 2025-04-09T16:00:55Z
author_association: COLLABORATOR
diff_hunk: @@ -166,6 +188,48 @@
     type: str
     returned: always
     sample: Microsoft.RecoveryServices/vaults/backupPolicies
+properties:
+    description:
+        - Attributes of the backup policy.
+    type: complex
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: ```suggestion
    type: dict
```
created_at: 2025-04-09T16:15:10Z
author_association: COLLABORATOR
diff_hunk: @@ -78,6 +78,48 @@
     type: str
     returned: always
     sample: Microsoft.RecoveryServices/vaults/backupPolicies
+properties:
+    description:
+        - Attributes of the backup policy.
+    type: complex
path: plugins/modules/azure_rm_backuppolicy_info.py
user: login: Fred-sun
body: ```suggestion
    type: dict
```
created_at: 2025-04-09T16:15:33Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long, over than 160
```suggestion
                if self.schedule_run_frequency is not None and
                   self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
```
created_at: 2025-04-09T16:17:49Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long

created_at: 2025-04-09T16:18:20Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long, over than 160
created_at: 2025-04-09T16:18:20Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long, over than 160
created_at: 2025-04-09T16:18:25Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
+                    self.results['changed'] = True
+                elif self.weekly_retention_count is not None and self.weekly_retention_count != old_res['properties']['retention_policy'].get('weekly_schedule', {}).get('retention_duration', {}).get('count'):
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long, over than 160
created_at: 2025-04-09T16:18:28Z
author_association: COLLABORATOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
+                    self.results['changed'] = True
+                elif self.weekly_retention_count is not None and self.weekly_retention_count != old_res['properties']['retention_policy'].get('weekly_schedule', {}).get('retention_duration', {}).get('count'):
+                    self.results['changed'] = True
+                elif self.daily_retention_count is not None and self.daily_retention_count != old_res['properties']['retention_policy'].get('daily_schedule', {}).get('retention_duration', {}).get('count'):
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Fred-sun
body: line too long, over than 160
created_at: 2025-04-09T16:20:01Z
author_association: COLLABORATOR
diff_hunk: @@ -166,3 +230,4 @@
   ansible.builtin.assert:
     that:
       - not weekly_policy_output_delete_idempotent.changed
+
path: tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
user: login: Klaas-
body: ansible-lint suggests you add an new line char at the end https://yamllint.readthedocs.io/en/stable/rules.html#module-yamllint.rules.new_line_at_end_of_file
created_at: 2025-04-10T06:58:03Z
author_association: CONTRIBUTOR
diff_hunk: @@ -166,6 +188,48 @@
     type: str
     returned: always
     sample: Microsoft.RecoveryServices/vaults/backupPolicies
+properties:
+    description:
+        - Attributes of the backup policy.
+    type: complex
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:58:26Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:58:47Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:58:51Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
+                    self.results['changed'] = True
+                elif self.weekly_retention_count is not None and self.weekly_retention_count != old_res['properties']['retention_policy'].get('weekly_schedule', {}).get('retention_duration', {}).get('count'):
+                    self.results['changed'] = True
+                elif self.daily_retention_count is not None and self.daily_retention_count != old_res['properties']['retention_policy'].get('daily_schedule', {}).get('retention_duration', {}).get('count'):
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:58:57Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:59:23Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:59:28Z
author_association: CONTRIBUTOR
diff_hunk: @@ -255,28 +318,50 @@ def exec_module(self, **kwargs):
                     return self.results
 
                 response = self.create_or_update_backup_policy()
-                self.set_results(response)
+                self.results.update(self.set_results(response))
 
             # log that we're doing an update
             else:
                 self.log("Backup policy {0} for vault {1} in resource group {2} already exists, updating".format(self.name,
                                                                                                                  self.vault_name,
                                                                                                                  self.resource_group))
-
-                self.results['changed'] = True
+                if self.schedule_run_frequency is not None and self.schedule_run_frequency != old_res['properties']['schedule_policy']['schedule_run_frequency']:
+                    self.results['changed'] = True
+                elif self.time_zone is not None and self.time_zone != old_res['properties']['time_zone']:
+                    self.results['changed'] = True
+                elif self.instant_recovery_snapshot_retention is not None and self.instant_recovery_snapshot_retention != old_res['properties']['instant_rp_retention_range_in_days']:
+                    self.results['changed'] = True
+                elif self.schedule_weekly_frequency is not None and self.schedule_weekly_frequency != old_res['properties']['schedule_policy']['schedule_weekly_frequency']:
+                    self.results['changed'] = True
+                elif self.weekly_retention_count is not None and self.weekly_retention_count != old_res['properties']['retention_policy'].get('weekly_schedule', {}).get('retention_duration', {}).get('count'):
path: plugins/modules/azure_rm_backuppolicy.py
user: login: Klaas-
body: addressed via rebase on top of your commits in #1890 
created_at: 2025-04-10T06:59:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -166,3 +230,4 @@
   ansible.builtin.assert:
     that:
       - not weekly_policy_output_delete_idempotent.changed
+
path: tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
user: login: Fred-sun
body: @Klaas- Preferably not, because errors are reported when lint checks.
created_at: 2025-04-14T08:50:52Z
author_association: COLLABORATOR
diff_hunk: @@ -166,3 +230,4 @@
   ansible.builtin.assert:
     that:
       - not weekly_policy_output_delete_idempotent.changed
+
path: tests/integration/targets/azure_rm_backuppolicy/tasks/main.yml
user: login: Klaas-
body: done
created_at: 2025-04-14T08:56:13Z
author_association: CONTRIBUTOR

PR comments:
user: login: Klaas-
created_at: 2025-04-08T14:55:24Z
body: Am I missing something or is `response = self.recovery_services_backup_client.protection_policies.create_or_update(...` simply giving back {} for V2? :) is that on purpose? I'll check on the API level
author_association: CONTRIBUTOR
user: login: Klaas-
created_at: 2025-04-08T15:07:25Z
body: on the api level it is correct, am I missing something on how the response gets created in `self.recovery_services_backup_client.protection_policies.create_or_update(...` or is this a python-sdk problem?
author_association: CONTRIBUTOR
user: login: Klaas-
created_at: 2025-04-09T13:16:47Z
body: I have rebased it on #1890 - it works as expected now. It does not introduce additional sanity failures to #1890 , but I did not fix the ones from https://github.com/ansible-collections/azure/pull/1890#issuecomment-2789665157 
author_association: CONTRIBUTOR
user: login: Klaas-
created_at: 2025-04-09T14:08:35Z
body: and I also changed the integration tests to work, this should apply nicely after #1890 is merged -- if you do additional changes to #1890 I'll rebase on top of them
author_association: CONTRIBUTOR
user: login: Klaas-
created_at: 2025-04-11T13:04:13Z
body: rebased on dev, should now merge nicely
author_association: CONTRIBUTOR
user: login: xuzhang3
created_at: 2025-04-16T06:42:23Z
body: @Klaas  please have resolve the file conflict
author_association: COLLABORATOR
user: login: Klaas-
created_at: 2025-04-16T08:03:53Z
body: I think it should be correct now, rebased on current dev
author_association: CONTRIBUTOR