From 99b8b9b2f7df66a46ea3a67d7868dea03d941fdc Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Wed, 1 Jun 2022 12:46:49 +0200 Subject: [PATCH] Apply suggestions Signed-off-by: Alina Buzachis --- plugins/modules/rds_cluster_snapshot.py | 57 +++++++++-------- .../targets/rds_cluster_snapshot/aliases | 1 + .../rds_cluster_snapshot/tasks/main.yml | 62 +++++++++---------- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/plugins/modules/rds_cluster_snapshot.py b/plugins/modules/rds_cluster_snapshot.py index 6e136facd46..5523af974d0 100644 --- a/plugins/modules/rds_cluster_snapshot.py +++ b/plugins/modules/rds_cluster_snapshot.py @@ -10,7 +10,7 @@ DOCUMENTATION = r''' --- module: rds_cluster_snapshot -version_added: 3.3.0 +version_added: 4.0.0 short_description: Manage Amazon RDS snapshots of DB clusters description: - Create, modify and delete RDS snapshots of DB clusters. @@ -21,7 +21,7 @@ default: present choices: [ 'present', 'absent'] type: str - db_snapshot_identifier: + db_cluster_snapshot_identifier: description: - The identifier of the DB cluster snapshot. required: true @@ -40,12 +40,12 @@ type: str source_db_cluster_snapshot_identifier: description: - - The identifier of the DB cluster snapshot to copy. - - If the source snapshot is in the same AWS region as the copy, specify the snapshot's identifier. - - If the source snapshot is in a different AWS region as the copy, specify the snapshot's ARN. + - The identifier of the DB cluster snapshot to copy. + - If the source snapshot is in the same AWS region as the copy, specify the snapshot's identifier. + - If the source snapshot is in a different AWS region as the copy, specify the snapshot's ARN. aliases: - - source_id - - source_snapshot_id + - source_id + - source_snapshot_id type: str source_region: description: @@ -53,7 +53,7 @@ type: str copy_tags: description: - - Whether to copy all tags from I(source_db_cluster_snapshot_identifier) to I(db_snapshot_identifier). + - Whether to copy all tags from I(source_db_cluster_snapshot_identifier) to I(db_cluster_snapshot_identifier). type: bool default: False wait: @@ -66,35 +66,30 @@ - How long before wait gives up, in seconds. default: 300 type: int - tags: - description: - - The tags to be assigned to the DB cluster snapshot. - type: dict - purge_tags: - description: - - Whether to remove tags not present in the C(tags) parameter. - default: true - type: bool +notes: + - Retrieve the information about a specific DB cluster or list the DB cluster snapshots for a specific DB cluster + can de done using M(community.aws.rds_snapshot_info) author: - - Alina Buzachis (@alinabuzachis) + - Alina Buzachis (@alinabuzachis) extends_documentation_fragment: -- amazon.aws.aws -- amazon.aws.ec2 + - amazon.aws.aws + - amazon.aws.ec2 + - amazon.aws.tags ''' EXAMPLES = r''' - name: Create a DB cluster snapshot community.aws.rds_cluster_snapshot: db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: new-cluster-snapshot + db_cluster_snapshot_identifier: new-cluster-snapshot - name: Delete a DB cluster snapshot community.aws.rds_cluster_snapshot: - db_snapshot_identifier: new-cluster-snapshot + db_cluster_snapshot_identifier: new-cluster-snapshot state: absent - name: Copy snapshot from a different region and copy its tags - community.aws.rds_instance_snapshot: + community.aws.rds_cluster_snapshot: id: new-database-snapshot-copy region: us-east-1 source_id: "{{ snapshot.db_snapshot_arn }}" @@ -198,7 +193,7 @@ type: str sample: arn:aws:rds:us-west-2:123456789012:snapshot:ansible-test-16638696-test-snapshot source_db_cluster_snapshot_arn: - description: If the DB cluster snapshot was copied from a source DB cluster snapshot, the Amazon Resource Name (ARN) for the source DB cluster snapshot, otherwise, a null value. + description: If the DB cluster snapshot was copied from a source DB cluster snapshot, the ARN for the source DB cluster snapshot, otherwise, null. returned: always type: str sample: null @@ -243,6 +238,8 @@ def get_snapshot(snapshot_id): snapshot["Tags"] = get_tags(client, module, snapshot["DBClusterSnapshotArn"]) except is_boto3_error_code("DBClusterSnapshotNotFound"): return {} + except is_boto3_error_code("DBClusterSnapshotNotFoundFault"): # pylint: disable=duplicate-except + return {} except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Couldn't get snapshot {0}".format(snapshot_id)) return snapshot @@ -263,7 +260,7 @@ def get_parameters(parameters, method_name): def ensure_snapshot_absent(): - snapshot_name = module.params.get("db_snapshot_identifier") + snapshot_name = module.params.get("db_cluster_snapshot_identifier") params = {"DBClusterSnapshotIdentifier": snapshot_name} changed = False @@ -285,16 +282,18 @@ def copy_snapshot(params): method_params = get_parameters(params, 'copy_db_cluster_snapshot') if method_params.get('Tags'): method_params['Tags'] = ansible_dict_to_boto3_tag_list(method_params['Tags']) - result, changed = call_method(client, module, 'copy_db__cluster_snapshot', method_params) + result, changed = call_method(client, module, 'copy_db_cluster_snapshot', method_params) return changed def ensure_snapshot_present(params): source_id = module.params.get('source_db_cluster_snapshot_identifier') - snapshot_name = module.params.get("db_snapshot_identifier") + snapshot_name = module.params.get("db_cluster_snapshot_identifier") changed = False + snapshot = get_snapshot(snapshot_name) + # Copy snapshot if source_id: changed |= copy_snapshot(params) @@ -338,12 +337,12 @@ def main(): argument_spec = dict( state=dict(type='str', choices=['present', 'absent'], default='present'), - db_snapshot_identifier=dict(type='str', aliases=['id', 'snapshot_id', 'snapshot_name'], required=True), + db_cluster_snapshot_identifier=dict(type='str', aliases=['id', 'snapshot_id', 'snapshot_name'], required=True), db_cluster_identifier=dict(type='str', aliases=['cluster_id', 'cluster_name']), source_db_cluster_snapshot_identifier=dict(type='str', aliases=['source_id', 'source_snapshot_id']), wait=dict(type='bool', default=False), wait_timeout=dict(type='int', default=300), - tags=dict(type='dict'), + tags=dict(type='dict', aliases=['resource_tags']), purge_tags=dict(type='bool', default=True), copy_tags=dict(type='bool', default=False), source_region=dict(type='str'), diff --git a/tests/integration/targets/rds_cluster_snapshot/aliases b/tests/integration/targets/rds_cluster_snapshot/aliases index ea05cc70efc..e9ea741b75a 100644 --- a/tests/integration/targets/rds_cluster_snapshot/aliases +++ b/tests/integration/targets/rds_cluster_snapshot/aliases @@ -1,2 +1,3 @@ cloud/aws +rds_snapshot_info diff --git a/tests/integration/targets/rds_cluster_snapshot/tasks/main.yml b/tests/integration/targets/rds_cluster_snapshot/tasks/main.yml index 7f50a1ce375..f3bd583ed31 100644 --- a/tests/integration/targets/rds_cluster_snapshot/tasks/main.yml +++ b/tests/integration/targets/rds_cluster_snapshot/tasks/main.yml @@ -61,7 +61,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}" + db_cluster_snapshot_identifier: "{{ snapshot_id }}" check_mode: true register: _result_cluster_snapshot @@ -73,7 +73,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}" + db_cluster_snapshot_identifier: "{{ snapshot_id }}" wait: true register: _result_cluster_snapshot @@ -89,8 +89,8 @@ - "'db_cluster_snapshot_arn' in _result_cluster_snapshot" - "'engine' in _result_cluster_snapshot" - _result_cluster_snapshot.engine == "{{ engine }}" - - "'engine_mode' in _result_cluster_snapshot" - - _result_cluster_snapshot.engine_mode == "provisioned" + # - "'engine_mode' in _result_cluster_snapshot" + # - _result_cluster_snapshot.engine_mode == "provisioned" - "'engine_version' in _result_cluster_snapshot" - "'iam_database_authentication_enabled' in _result_cluster_snapshot" - "'license_model' in _result_cluster_snapshot" @@ -165,7 +165,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}-b" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" wait: true register: _result_cluster_snapshot @@ -181,8 +181,8 @@ - "'db_cluster_snapshot_arn' in _result_cluster_snapshot" - "'engine' in _result_cluster_snapshot" - _result_cluster_snapshot.engine == "{{ engine }}" - - "'engine_mode' in _result_cluster_snapshot" - - _result_cluster_snapshot.engine_mode == "provisioned" + # - "'engine_mode' in _result_cluster_snapshot" + # - _result_cluster_snapshot.engine_mode == "provisioned" - "'engine_version' in _result_cluster_snapshot" - "'iam_database_authentication_enabled' in _result_cluster_snapshot" - "'license_model' in _result_cluster_snapshot" @@ -209,7 +209,7 @@ - name: Delete existing DB cluster snapshot (CHECK_MODE) rds_cluster_snapshot: state: absent - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" register: _result_delete_snapshot check_mode: true @@ -220,7 +220,7 @@ - name: Delete the existing DB cluster snapshot rds_cluster_snapshot: state: absent - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" register: _result_delete_snapshot - assert: @@ -240,7 +240,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" wait: true tags: tag_one: '{{ snapshot_id }}-b One' @@ -259,8 +259,8 @@ - "'db_cluster_snapshot_arn' in _result_cluster_snapshot" - "'engine' in _result_cluster_snapshot" - _result_cluster_snapshot.engine == "{{ engine }}" - - "'engine_mode' in _result_cluster_snapshot" - - _result_cluster_snapshot.engine_mode == "provisioned" + # - "'engine_mode' in _result_cluster_snapshot" + # - _result_cluster_snapshot.engine_mode == "provisioned" - "'engine_version' in _result_cluster_snapshot" - "'iam_database_authentication_enabled' in _result_cluster_snapshot" - "'license_model' in _result_cluster_snapshot" @@ -281,7 +281,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" wait: true tags: tag_one: '{{ snapshot_id }}-b One' @@ -296,7 +296,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" tags: tag_three: '{{ snapshot_id }}-b Three' "Tag Two": 'two {{ snapshot_id }}-b' @@ -314,8 +314,8 @@ - "'db_cluster_snapshot_arn' in _result_cluster_snapshot" - "'engine' in _result_cluster_snapshot" - _result_cluster_snapshot.engine == "{{ engine }}" - - "'engine_mode' in _result_cluster_snapshot" - - _result_cluster_snapshot.engine_mode == "provisioned" + # - "'engine_mode' in _result_cluster_snapshot" + # - _result_cluster_snapshot.engine_mode == "provisioned" - "'engine_version' in _result_cluster_snapshot" - "'iam_database_authentication_enabled' in _result_cluster_snapshot" - "'license_model' in _result_cluster_snapshot" @@ -336,7 +336,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" purge_tags: false tags: tag_one: '{{ snapshot_id }}-b One' @@ -354,8 +354,8 @@ - "'db_cluster_snapshot_arn' in _result_cluster_snapshot" - "'engine' in _result_cluster_snapshot" - _result_cluster_snapshot.engine == "{{ engine }}" - - "'engine_mode' in _result_cluster_snapshot" - - _result_cluster_snapshot.engine_mode == "provisioned" + # - "'engine_mode' in _result_cluster_snapshot" + # - _result_cluster_snapshot.engine_mode == "provisioned" - "'engine_version' in _result_cluster_snapshot" - "'iam_database_authentication_enabled' in _result_cluster_snapshot" - "'license_model' in _result_cluster_snapshot" @@ -377,7 +377,7 @@ rds_cluster_snapshot: state: present db_cluster_identifier: "{{ cluster_id }}" - db_snapshot_identifier: "{{ snapshot_id }}-b" + db_cluster_snapshot_identifier: "{{ snapshot_id }}-b" register: _result_cluster_snapshot - assert: @@ -386,13 +386,13 @@ # ------------------------------------------------------------------------------------------ # Test copying a snapshot - ### Copying a snapshot from a different region is supported, but not in CI, + ### Copying a DB cluster snapshot from a different region is supported, but not in CI, ### because the aws-terminator only terminates resources in one region. - set_fact: _snapshot_arn: "{{ _result_cluster_snapshot.db_cluster_snapshot_arn }}" - - name: Copy a snapshot (check mode) - rds_instance_snapshot: + - name: Copy a DB cluster snapshot (check mode) + rds_cluster_snapshot: id: "{{ snapshot_id }}-copy" source_id: "{{ snapshot_id }}-b" copy_tags: yes @@ -404,8 +404,8 @@ that: - _result_cluster_copy_snapshot.changed - - name: Copy a snapshot - rds_instance_snapshot: + - name: Copy a DB cluster snapshot + rds_cluster_snapshot: id: "{{ snapshot_id }}-copy" source_id: "{{ snapshot_id }}-b" copy_tags: yes @@ -424,8 +424,8 @@ - _result_cluster_copy_snapshot.tags["Tag Two"] == "two {{ snapshot_id }}-b" - _result_cluster_copy_snapshot.tags["tag_three"] == "{{ snapshot_id }}-b Three" - - name: Copy a snapshot (idempotence - check mode) - rds_instance_snapshot: + - name: Copy a DB cluster snapshot (idempotence - check mode) + rds_cluster_snapshot: id: "{{ snapshot_id }}-copy" source_id: "{{ snapshot_id }}-b" copy_tags: yes @@ -437,8 +437,8 @@ that: - not _result_cluster_copy_snapshot.changed - - name: Copy a snapshot (idempotence) - rds_instance_snapshot: + - name: Copy a DB cluster snapshot (idempotence) + rds_cluster_snapshot: id: "{{ snapshot_id }}-copy" source_id: "{{ snapshot_id }}-b" copy_tags: yes @@ -448,7 +448,7 @@ - assert: that: - not _result_cluster_copy_snapshot.changed - - _result_cluster_copy_snapshot.db_instance_identifier == "{{ cluster_id }}" + - _result_cluster_copy_snapshot.db_cluster_identifier == "{{ cluster_id }}" - _result_cluster_copy_snapshot.source_db_cluster_snapshot_arn == "{{ _snapshot_arn }}" - _result_cluster_copy_snapshot.db_cluster_snapshot_identifier == "{{ snapshot_id }}-copy" - "'tags' in _result_cluster_copy_snapshot" @@ -461,7 +461,7 @@ - name: Delete the existing DB cluster snapshots rds_cluster_snapshot: state: absent - db_snapshot_identifier: "{{ item }}" + db_cluster_snapshot_identifier: "{{ item }}" register: _result_delete_snapshot ignore_errors: true loop: