1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[cloud] Amazon Redshift module cluster deletion fix (#25164)

* Fix typo (#25161)

* Fixed cluster deletion: added final snapshot management

This adds 2 new options to the module API (only for the "delete" command):

* skip_final_cluster_snapshot: skip a final snapshot before deleting the cluster
* final_cluster_snapshot_identifier: identifier of the final snapshot to be created before deleting the cluster

Ref: http://boto.cloudhackers.com/en/latest/ref/redshift.html

* Fixed cluster deletion: added final snapshot management

This adds 2 new options to the module API (only for the "delete" command):

* skip_final_cluster_snapshot: skip a final snapshot before deleting the cluster
* final_cluster_snapshot_identifier: identifier of the final snapshot to be created before deleting the cluster

Ref: http://boto.cloudhackers.com/en/latest/ref/redshift.html

* add version_added information

* Review corrections:

* used required_if instead of checking parameters compatibility inside the code
* renamed aliases to be more explicit

Also added an example for the "delete" command

* Review corrections correction - make "delete" command specific parameters mandatory only when the command is "delete"

* updated doc with aliases

* Fix YAML docs syntax

* Set default to match API for skip_final_cluster_snapshot.
This commit is contained in:
banzo 2017-08-24 22:41:32 +02:00 committed by Ryan Brown
parent 7a182fc43e
commit 3302248616

View file

@ -80,6 +80,19 @@ options:
- VPC security group - VPC security group
aliases: ['vpc_security_groups'] aliases: ['vpc_security_groups']
default: null default: null
skip_final_cluster_snapshot:
description:
- skip a final snapshot before deleting the cluster. Used only when command=delete.
aliases: ['skip_final_snapshot']
default: false
version_added: "2.4"
final_cluster_snapshot_identifier:
description:
- identifier of the final snapshot to be created before deleting the cluster. If this parameter is provided,
final_cluster_snapshot_identifier must be false. Used only when command=delete.
aliases: ['final_snapshot_id']
default: null
version_added: "2.4"
preferred_maintenance_window: preferred_maintenance_window:
description: description:
- maintenance window - maintenance window
@ -149,6 +162,13 @@ EXAMPLES = '''
identifier=new_cluster identifier=new_cluster
username=cluster_admin username=cluster_admin
password=1nsecure password=1nsecure
# Cluster delete example
- redshift:
command: delete
identifier: new_cluster
skip_final_cluster_snapshot: true
wait: true
''' '''
RETURN = ''' RETURN = '''
@ -327,12 +347,18 @@ def delete_cluster(module, redshift):
redshift: authenticated redshift connection object redshift: authenticated redshift connection object
""" """
identifier = module.params.get('identifier') identifier = module.params.get('identifier')
wait = module.params.get('wait') wait = module.params.get('wait')
wait_timeout = module.params.get('wait_timeout') wait_timeout = module.params.get('wait_timeout')
skip_final_cluster_snapshot = module.params.get('skip_final_cluster_snapshot')
final_cluster_snapshot_identifier = module.params.get('final_cluster_snapshot_identifier')
try: try:
redshift.delete_custer( identifier ) redshift.delete_cluster(
identifier,
skip_final_cluster_snapshot,
final_cluster_snapshot_identifier
)
except boto.exception.JSONResponseError as e: except boto.exception.JSONResponseError as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
@ -422,6 +448,8 @@ def main():
cluster_type = dict(choices=['multi-node', 'single-node', ], default='single-node'), cluster_type = dict(choices=['multi-node', 'single-node', ], default='single-node'),
cluster_security_groups = dict(aliases=['security_groups'], type='list'), cluster_security_groups = dict(aliases=['security_groups'], type='list'),
vpc_security_group_ids = dict(aliases=['vpc_security_groups'], type='list'), vpc_security_group_ids = dict(aliases=['vpc_security_groups'], type='list'),
skip_final_cluster_snapshot = dict(aliases=['skip_final_snapshot'], type='bool', default=False),
final_cluster_snapshot_identifier = dict(aliases=['final_snapshot_id'], required=False),
cluster_subnet_group_name = dict(aliases=['subnet']), cluster_subnet_group_name = dict(aliases=['subnet']),
availability_zone = dict(aliases=['aws_zone', 'zone']), availability_zone = dict(aliases=['aws_zone', 'zone']),
preferred_maintenance_window = dict(aliases=['maintance_window', 'maint_window']), preferred_maintenance_window = dict(aliases=['maintance_window', 'maint_window']),
@ -437,11 +465,16 @@ def main():
new_cluster_identifier = dict(aliases=['new_identifier']), new_cluster_identifier = dict(aliases=['new_identifier']),
wait = dict(type='bool', default=False), wait = dict(type='bool', default=False),
wait_timeout = dict(type='int', default=300), wait_timeout = dict(type='int', default=300),
) ))
)
required_if = [
('command', 'delete', ['skip_final_cluster_snapshot']),
('skip_final_cluster_snapshot', False, ['final_cluster_snapshot_identifier'])
]
module = AnsibleModule( module = AnsibleModule(
argument_spec=argument_spec, argument_spec=argument_spec,
required_if=required_if
) )
if not HAS_BOTO: if not HAS_BOTO: