diff --git a/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml b/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml new file mode 100644 index 00000000000..96bedc378bc --- /dev/null +++ b/changelogs/fragments/2083-backup_plan_info-bugfix-get-info-for-all-plans.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - backup_plan_info - Bugfix to enable getting info of all backup plans (https://github.com/ansible-collections/amazon.aws/pull/2083). diff --git a/plugins/modules/backup_plan_info.py b/plugins/modules/backup_plan_info.py index 096857d5b1f..98f49f6b6e5 100644 --- a/plugins/modules/backup_plan_info.py +++ b/plugins/modules/backup_plan_info.py @@ -20,7 +20,6 @@ backup_plan_names: type: list elements: str - required: true description: - Specifies a list of plan names. extends_documentation_fragment: @@ -31,10 +30,11 @@ EXAMPLES = r""" # Note: These examples do not set authentication details, see the AWS Guide for details. -# Gather information about all backup plans -- amazon.aws.backup_plan_info -# Gather information about a particular backup plan -- amazon.aws.backup_plan_info: +- name: Gather information about all backup plans + amazon.aws.backup_plan_info: + +- name: Gather information about a particular backup plan + amazon.aws.backup_plan_info: backup plan_names: - elastic """ @@ -110,10 +110,21 @@ from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry +def get_all_backup_plans_info(client): + paginator = client.get_paginator("list_backup_plans") + return paginator.paginate().build_full_result() + + def get_backup_plan_detail(client, module): backup_plan_list = [] backup_plan_names = module.params.get("backup_plan_names") + if backup_plan_names is None: + backup_plan_names = [] + backup_plan_list_info = get_all_backup_plans_info(client)["BackupPlansList"] + for backup_plan in backup_plan_list_info: + backup_plan_names.append(backup_plan["BackupPlanName"]) + for name in backup_plan_names: backup_plan_list.extend(get_plan_details(module, client, name)) @@ -122,7 +133,7 @@ def get_backup_plan_detail(client, module): def main(): argument_spec = dict( - backup_plan_names=dict(type="list", elements="str", required=True), + backup_plan_names=dict(type="list", elements="str"), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) diff --git a/tests/integration/targets/backup_plan/tasks/main.yml b/tests/integration/targets/backup_plan/tasks/main.yml index ee8f62ec9a5..79e6e147953 100644 --- a/tests/integration/targets/backup_plan/tasks/main.yml +++ b/tests/integration/targets/backup_plan/tasks/main.yml @@ -344,12 +344,41 @@ - backup_plan_create_result.exists is true - backup_plan_create_result.changed is false + - name: Create another backup plan + amazon.aws.backup_plan: + backup_plan_name: "{{ backup_plan_name }}-1" + rules: + - rule_name: daily + target_backup_vault_name: "{{ backup_vault_name }}" + tags: + Environment: Test + register: backup_plan_create_result_1 + + - name: Verify backup plan create result + ansible.builtin.assert: + that: + - backup_plan_create_result_1.exists is true + - backup_plan_create_result_1.changed is true + + - name: Get info of all install plans + amazon.aws.backup_plan_info: + register: backup_plan_info_result + + - name: Assert that info of all backup plans is fetched + ansible.builtin.assert: + that: + - backup_plan_info_result is not failed + - backup_plan_info_result.backup_plans | length > 1 + always: - name: Delete AWS Backup plan created during this test amazon.aws.backup_plan: - backup_plan_name: "{{ backup_plan_name }}" + backup_plan_name: "{{ item }}" state: absent ignore_errors: true + with_items: + - "{{ backup_plan_name }}" + - "{{ backup_plan_name }}-1" - name: Delete AWS Backup vault created during this test amazon.aws.backup_vault: