Allow explict setting of vpc_security_groups to allow modification of security groups of RDS instances within a VPC

This commit is contained in:
Mohan Krishnan 2014-02-10 11:42:15 +07:00
parent 7e34f4d885
commit 1fa0b3365e

View file

@ -119,7 +119,13 @@ options:
aliases: [] aliases: []
security_groups: security_groups:
description: description:
- Comma separated list of one or more security groups. Used only when command=create or command=modify. If a subnet is specified then this is treated as a list of VPC security groups. - Comma separated list of one or more security groups. Used only when command=create or command=modify.
required: false
default: null
aliases: []
vpc_security_groups:
description:
- Comma separated list of one or more vpc security groups. Used only when command=create or command=modify.
required: false required: false
default: null default: null
aliases: [] aliases: []
@ -294,6 +300,7 @@ def main():
multi_zone = dict(type='bool', default=False), multi_zone = dict(type='bool', default=False),
iops = dict(required=False), iops = dict(required=False),
security_groups = dict(required=False), security_groups = dict(required=False),
vpc_security_groups = dict(required=False),
port = dict(required=False), port = dict(required=False),
upgrade = dict(type='bool', default=False), upgrade = dict(type='bool', default=False),
option_group = dict(required=False), option_group = dict(required=False),
@ -328,6 +335,7 @@ def main():
multi_zone = module.params.get('multi_zone') multi_zone = module.params.get('multi_zone')
iops = module.params.get('iops') iops = module.params.get('iops')
security_groups = module.params.get('security_groups') security_groups = module.params.get('security_groups')
vpc_security_groups = module.params.get('vpc_security_groups')
port = module.params.get('port') port = module.params.get('port')
upgrade = module.params.get('upgrade') upgrade = module.params.get('upgrade')
option_group = module.params.get('option_group') option_group = module.params.get('option_group')
@ -355,40 +363,46 @@ def main():
except boto.exception.BotoServerError, e: except boto.exception.BotoServerError, e:
module.fail_json(msg = e.error_message) module.fail_json(msg = e.error_message)
def invalid_security_group_type(subnet):
if subnet:
return 'security_groups'
else:
return 'vpc_security_groups'
# Validate parameters for each command # Validate parameters for each command
if command == 'create': if command == 'create':
required_vars = [ 'instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password' ] required_vars = [ 'instance_name', 'db_engine', 'size', 'instance_type', 'username', 'password' ]
invalid_vars = [ 'source_instance', 'snapshot', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'source_instance', 'snapshot', 'apply_immediately', 'new_instance_name' ] + [invalid_security_group_type(subnet)]
elif command == 'replicate': elif command == 'replicate':
required_vars = [ 'instance_name', 'source_instance' ] required_vars = [ 'instance_name', 'source_instance' ]
invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'subnet', 'snapshot', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'vpc_security_groups', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'subnet', 'snapshot', 'apply_immediately', 'new_instance_name' ]
elif command == 'delete': elif command == 'delete':
required_vars = [ 'instance_name' ] required_vars = [ 'instance_name' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone' , 'source_instance', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'vpc_security_groups' ,'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone' , 'source_instance', 'apply_immediately', 'new_instance_name' ]
elif command == 'facts': elif command == 'facts':
required_vars = [ 'instance_name' ] required_vars = [ 'instance_name' ]
invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone', 'wait', 'source_instance' 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'size', 'instance_type', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'vpc_security_groups', 'security_groups', 'option_group', 'maint_window', 'backup_window', 'backup_retention', 'port', 'upgrade', 'subnet', 'zone', 'wait', 'source_instance' 'apply_immediately', 'new_instance_name' ]
elif command == 'modify': elif command == 'modify':
required_vars = [ 'instance_name' ] required_vars = [ 'instance_name' ]
if password: if password:
params["master_password"] = password params["master_password"] = password
invalid_vars = [ 'db_engine', 'username', 'db_name', 'engine_version', 'license_model', 'option_group', 'port', 'upgrade', 'subnet', 'zone', 'source_instance' ] invalid_vars = [ 'db_engine', 'username', 'db_name', 'engine_version', 'license_model', 'option_group', 'port', 'upgrade', 'subnet', 'zone', 'source_instance']
elif command == 'promote': elif command == 'promote':
required_vars = [ 'instance_name' ] required_vars = [ 'instance_name' ]
invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'subnet', 'source_instance', 'snapshot', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'vpc_security_groups', 'security_groups', 'option_group', 'maint_window', 'subnet', 'source_instance', 'snapshot', 'apply_immediately', 'new_instance_name' ]
elif command == 'snapshot': elif command == 'snapshot':
required_vars = [ 'instance_name', 'snapshot'] required_vars = [ 'instance_name', 'snapshot']
invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'security_groups', 'option_group', 'maint_window', 'subnet', 'source_instance', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'size', 'username', 'password', 'db_name', 'engine_version', 'parameter_group', 'license_model', 'multi_zone', 'iops', 'vpc_security_groups', 'security_groups', 'option_group', 'maint_window', 'subnet', 'source_instance', 'apply_immediately', 'new_instance_name' ]
elif command == 'restore': elif command == 'restore':
required_vars = [ 'instance_name', 'snapshot', 'instance_type' ] required_vars = [ 'instance_name', 'snapshot', 'instance_type' ]
invalid_vars = [ 'db_engine', 'db_name', 'usernmae', 'password', 'engine_version', 'option_group', 'source_instance', 'apply_immediately', 'new_instance_name' ] invalid_vars = [ 'db_engine', 'db_name', 'username', 'password', 'engine_version', 'option_group', 'source_instance', 'apply_immediately', 'new_instance_name', 'vpc_security_groups', 'security_groups' ]
for v in required_vars: for v in required_vars:
if not module.params.get(v): if not module.params.get(v):
@ -447,10 +461,10 @@ def main():
params["iops"] = iops params["iops"] = iops
if security_groups: if security_groups:
if subnet: params["security_groups"] = security_groups.split(',')
params["vpc_security_groups"] = security_groups.split(',')
else: if vpc_security_groups:
params["security_groups"] = security_groups.split(',') params["vpc_security_groups"] = vpc_security_groups.split(',')
if new_instance_name: if new_instance_name:
params["new_instance_id"] = new_instance_name params["new_instance_id"] = new_instance_name