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
|
@ -179,7 +179,7 @@ snapshots:
|
||||||
sample: gp2
|
sample: gp2
|
||||||
tags:
|
tags:
|
||||||
description: Snapshot tags
|
description: Snapshot tags
|
||||||
returned: always
|
returned: when snapshot is not shared
|
||||||
type: complex
|
type: complex
|
||||||
contains: {}
|
contains: {}
|
||||||
vpc_id:
|
vpc_id:
|
||||||
|
@ -286,7 +286,7 @@ cluster_snapshots:
|
||||||
sample: true
|
sample: true
|
||||||
tags:
|
tags:
|
||||||
description: Tags of the snapshot
|
description: Tags of the snapshot
|
||||||
returned: always
|
returned: when snapshot is not shared
|
||||||
type: complex
|
type: complex
|
||||||
contains: {}
|
contains: {}
|
||||||
vpc_id:
|
vpc_id:
|
||||||
|
@ -316,6 +316,7 @@ def common_snapshot_info(module, conn, method, prefix, params):
|
||||||
|
|
||||||
for snapshot in results:
|
for snapshot in results:
|
||||||
try:
|
try:
|
||||||
|
if snapshot['SnapshotType'] != 'shared':
|
||||||
snapshot['Tags'] = boto3_tag_list_to_ansible_dict(conn.list_tags_for_resource(ResourceName=snapshot['%sArn' % prefix],
|
snapshot['Tags'] = boto3_tag_list_to_ansible_dict(conn.list_tags_for_resource(ResourceName=snapshot['%sArn' % prefix],
|
||||||
aws_retry=True)['TagList'])
|
aws_retry=True)['TagList'])
|
||||||
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
|
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
|
||||||
|
@ -337,9 +338,9 @@ def cluster_snapshot_info(module, conn):
|
||||||
if snapshot_type:
|
if snapshot_type:
|
||||||
params['SnapshotType'] = snapshot_type
|
params['SnapshotType'] = snapshot_type
|
||||||
if snapshot_type == 'public':
|
if snapshot_type == 'public':
|
||||||
params['IsPublic'] = True
|
params['IncludePublic'] = True
|
||||||
elif snapshot_type == 'shared':
|
elif snapshot_type == 'shared':
|
||||||
params['IsShared'] = True
|
params['IncludeShared'] = True
|
||||||
|
|
||||||
return common_snapshot_info(module, conn, 'describe_db_cluster_snapshots', 'DBClusterSnapshot', params)
|
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:
|
if snapshot_type:
|
||||||
params['SnapshotType'] = snapshot_type
|
params['SnapshotType'] = snapshot_type
|
||||||
if snapshot_type == 'public':
|
if snapshot_type == 'public':
|
||||||
params['IsPublic'] = True
|
params['IncludePublic'] = True
|
||||||
elif snapshot_type == 'shared':
|
elif snapshot_type == 'shared':
|
||||||
params['IsShared'] = True
|
params['IncludeShared'] = True
|
||||||
|
|
||||||
return common_snapshot_info(module, conn, 'describe_db_snapshots', 'DBSnapshot', params)
|
return common_snapshot_info(module, conn, 'describe_db_snapshots', 'DBSnapshot', params)
|
||||||
|
|
||||||
|
|
|
@ -23,5 +23,7 @@
|
||||||
tags: vpc_security_groups
|
tags: vpc_security_groups
|
||||||
- include: ./test_restore_instance.yml # TODO: snapshot, s3
|
- include: ./test_restore_instance.yml # TODO: snapshot, s3
|
||||||
tags: restore
|
tags: restore
|
||||||
|
- include: ./test_snapshot.yml
|
||||||
|
tags: snapshot
|
||||||
# TODO: uncomment after adding rds_cluster module
|
# TODO: uncomment after adding rds_cluster module
|
||||||
#- include: ./test_aurora.yml
|
#- 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…
Reference in a new issue