Fix for shared snapshot parameter (#60250)
* Fix for shared snapshot parameter Fixing this bug: `Unknown parameter in input: "IsShared", must be one of: DBInstanceIdentifier, DBSnapshotIdentifier, SnapshotType, Filters, MaxRecords, Marker, IncludeShared, IncludePublic, DbiResourceId` * Updated documentation for shared snapshots Tags can't get accessed for shared snapshots * fixed indentation * added test for shared snapshot * fixed isPublic parameter to correct IncludePublic parameter Co-authored-by: Oliver Kastler <oliver@realestate.co.nz>
This commit is contained in:
parent
7ae34cef15
commit
0760a7ec08
3 changed files with 96 additions and 8 deletions
|
@ -179,7 +179,7 @@ snapshots:
|
|||
sample: gp2
|
||||
tags:
|
||||
description: Snapshot tags
|
||||
returned: always
|
||||
returned: when snapshot is not shared
|
||||
type: complex
|
||||
contains: {}
|
||||
vpc_id:
|
||||
|
@ -286,7 +286,7 @@ cluster_snapshots:
|
|||
sample: true
|
||||
tags:
|
||||
description: Tags of the snapshot
|
||||
returned: always
|
||||
returned: when snapshot is not shared
|
||||
type: complex
|
||||
contains: {}
|
||||
vpc_id:
|
||||
|
@ -316,8 +316,9 @@ def common_snapshot_info(module, conn, method, prefix, params):
|
|||
|
||||
for snapshot in results:
|
||||
try:
|
||||
snapshot['Tags'] = boto3_tag_list_to_ansible_dict(conn.list_tags_for_resource(ResourceName=snapshot['%sArn' % prefix],
|
||||
aws_retry=True)['TagList'])
|
||||
if snapshot['SnapshotType'] != 'shared':
|
||||
snapshot['Tags'] = boto3_tag_list_to_ansible_dict(conn.list_tags_for_resource(ResourceName=snapshot['%sArn' % prefix],
|
||||
aws_retry=True)['TagList'])
|
||||
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
|
||||
module.fail_json_aws(e, "Couldn't get tags for snapshot %s" % snapshot['%sIdentifier' % prefix])
|
||||
|
||||
|
@ -337,9 +338,9 @@ def cluster_snapshot_info(module, conn):
|
|||
if snapshot_type:
|
||||
params['SnapshotType'] = snapshot_type
|
||||
if snapshot_type == 'public':
|
||||
params['IsPublic'] = True
|
||||
params['IncludePublic'] = True
|
||||
elif snapshot_type == 'shared':
|
||||
params['IsShared'] = True
|
||||
params['IncludeShared'] = True
|
||||
|
||||
return common_snapshot_info(module, conn, 'describe_db_cluster_snapshots', 'DBClusterSnapshot', params)
|
||||
|
||||
|
@ -357,9 +358,9 @@ def standalone_snapshot_info(module, conn):
|
|||
if snapshot_type:
|
||||
params['SnapshotType'] = snapshot_type
|
||||
if snapshot_type == 'public':
|
||||
params['IsPublic'] = True
|
||||
params['IncludePublic'] = True
|
||||
elif snapshot_type == 'shared':
|
||||
params['IsShared'] = True
|
||||
params['IncludeShared'] = True
|
||||
|
||||
return common_snapshot_info(module, conn, 'describe_db_snapshots', 'DBSnapshot', params)
|
||||
|
||||
|
|
|
@ -23,5 +23,7 @@
|
|||
tags: vpc_security_groups
|
||||
- include: ./test_restore_instance.yml # TODO: snapshot, s3
|
||||
tags: restore
|
||||
- include: ./test_snapshot.yml
|
||||
tags: snapshot
|
||||
# TODO: uncomment after adding rds_cluster module
|
||||
#- include: ./test_aurora.yml
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
---
|
||||
- block:
|
||||
- name: set up aws connection info
|
||||
set_fact:
|
||||
aws_connection_info: &aws_connection_info
|
||||
aws_access_key: "{{ aws_access_key }}"
|
||||
aws_secret_key: "{{ aws_secret_key }}"
|
||||
security_token: "{{ security_token }}"
|
||||
region: "{{ aws_region }}"
|
||||
no_log: yes
|
||||
|
||||
- name: Getting shared snapshots
|
||||
rds_snapshot_info:
|
||||
snapshot_type: "shared"
|
||||
<<: *aws_connection_info
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not result.changed
|
||||
- result.cluster_snapshots is defined
|
||||
- result.snapshots is defined
|
||||
|
||||
- name: Ensure the resource doesn't exist
|
||||
rds_instance:
|
||||
db_instance_identifier: "{{ instance_id }}"
|
||||
state: absent
|
||||
skip_final_snapshot: True
|
||||
<<: *aws_connection_info
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not result.changed
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Create a mariadb instance
|
||||
rds_instance:
|
||||
db_instance_identifier: "{{ instance_id }}"
|
||||
state: present
|
||||
engine: mariadb
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
db_instance_class: "{{ db_instance_class }}"
|
||||
allocated_storage: "{{ allocated_storage }}"
|
||||
tags:
|
||||
Name: "{{ instance_id }}"
|
||||
Created_by: Ansible rds_instance tests
|
||||
<<: *aws_connection_info
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed
|
||||
- "result.db_instance_identifier == '{{ instance_id }}'"
|
||||
- "result.tags | length == 2"
|
||||
- "result.tags.Name == '{{ instance_id }}'"
|
||||
- "result.tags.Created_by == 'Ansible rds_instance tests'"
|
||||
|
||||
- name: Getting public snapshots
|
||||
rds_snapshot_info:
|
||||
db_instance_identifier: "{{ instance_id }}"
|
||||
snapshot_type: "public"
|
||||
<<: *aws_connection_info
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- not result.changed
|
||||
- result.cluster_snapshots is not defined
|
||||
- result.snapshots is defined
|
||||
|
||||
- name: Ensure the resource doesn't exist
|
||||
rds_instance:
|
||||
db_instance_identifier: "{{ instance_id }}"
|
||||
state: absent
|
||||
skip_final_snapshot: True
|
||||
<<: *aws_connection_info
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed
|
||||
|
||||
# TODO ideally we test with an actual shared snapshot - but we'd need a second account - making tests fairly complicated?
|
Loading…
Add table
Reference in a new issue