Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Alina Buzachis <[email protected]>
  • Loading branch information
alinabuzachis committed Jun 1, 2022
1 parent 2e14585 commit 4f7a535
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 55 deletions.
57 changes: 28 additions & 29 deletions plugins/modules/rds_cluster_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -40,20 +40,20 @@
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:
- The region that contains the snapshot to be copied.
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:
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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'),
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/rds_cluster_snapshot/aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cloud/aws

rds_snapshot_info
52 changes: 26 additions & 26 deletions tests/integration/targets/rds_cluster_snapshot/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -89,7 +89,7 @@
- "'db_cluster_snapshot_arn' in _result_cluster_snapshot"
- "'engine' in _result_cluster_snapshot"
- _result_cluster_snapshot.engine == "{{ engine }}"
- "'engine_mode' in _result_cluster_snapshot"
# - "'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"
Expand Down Expand Up @@ -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

Expand All @@ -181,7 +181,7 @@
- "'db_cluster_snapshot_arn' in _result_cluster_snapshot"
- "'engine' in _result_cluster_snapshot"
- _result_cluster_snapshot.engine == "{{ engine }}"
- "'engine_mode' in _result_cluster_snapshot"
# - "'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"
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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'
Expand All @@ -259,7 +259,7 @@
- "'db_cluster_snapshot_arn' in _result_cluster_snapshot"
- "'engine' in _result_cluster_snapshot"
- _result_cluster_snapshot.engine == "{{ engine }}"
- "'engine_mode' in _result_cluster_snapshot"
# - "'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"
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -314,7 +314,7 @@
- "'db_cluster_snapshot_arn' in _result_cluster_snapshot"
- "'engine' in _result_cluster_snapshot"
- _result_cluster_snapshot.engine == "{{ engine }}"
- "'engine_mode' in _result_cluster_snapshot"
# - "'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"
Expand All @@ -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'
Expand All @@ -354,7 +354,7 @@
- "'db_cluster_snapshot_arn' in _result_cluster_snapshot"
- "'engine' in _result_cluster_snapshot"
- _result_cluster_snapshot.engine == "{{ engine }}"
- "'engine_mode' in _result_cluster_snapshot"
# - "'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"
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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:
Expand Down

0 comments on commit 4f7a535

Please sign in to comment.