diff --git a/cloud/amazon/elasticache.py b/cloud/amazon/elasticache.py index 4e76d593cc9..18be34560a5 100644 --- a/cloud/amazon/elasticache.py +++ b/cloud/amazon/elasticache.py @@ -58,6 +58,12 @@ options: - The port number on which each of the cache nodes will accept connections required: false default: 11211 + cache_subnet_group: + description: + - The subnet group name to associate with. Only use if inside a vpc. Required if inside a vpc + required: conditional + default: None + version_added: "1.7" security_group_ids: description: - A list of vpc security group names to associate with this cache cluster. Only use if inside a vpc @@ -66,7 +72,7 @@ options: version_added: "1.6" cache_security_groups: description: - - A list of cache security group names to associate with this cache cluster + - A list of cache security group names to associate with this cache cluster. Must be an empty list if inside a vpc required: false default: ['default'] zone: @@ -155,7 +161,8 @@ class ElastiCacheManager(object): EXIST_STATUSES = ['available', 'creating', 'rebooting', 'modifying'] def __init__(self, module, name, engine, cache_engine_version, node_type, - num_nodes, cache_port, cache_security_groups, security_group_ids, zone, wait, + num_nodes, cache_port, cache_subnet_group, + cache_security_groups, security_group_ids, zone, wait, hard_modify, aws_access_key, aws_secret_key, region): self.module = module self.name = name @@ -164,6 +171,7 @@ class ElastiCacheManager(object): self.node_type = node_type self.num_nodes = num_nodes self.cache_port = cache_port + self.cache_subnet_group = cache_subnet_group self.cache_security_groups = cache_security_groups self.security_group_ids = security_group_ids self.zone = zone @@ -222,6 +230,7 @@ class ElastiCacheManager(object): engine_version=self.cache_engine_version, cache_security_group_names=self.cache_security_groups, security_group_ids=self.security_group_ids, + cache_subnet_group_name=self.cache_subnet_group, preferred_availability_zone=self.zone, port=self.cache_port) except boto.exception.BotoServerError, e: @@ -476,6 +485,7 @@ class ElastiCacheManager(object): def main(): argument_spec = ec2_argument_spec() + default = object() argument_spec.update(dict( state={'required': True, 'choices': ['present', 'absent', 'rebooted']}, name={'required': True}, @@ -484,7 +494,8 @@ def main(): node_type={'required': False, 'default': 'cache.m1.small'}, num_nodes={'required': False, 'default': None, 'type': 'int'}, cache_port={'required': False, 'default': 11211, 'type': 'int'}, - cache_security_groups={'required': False, 'default': ['default'], + cache_subnet_group={'required': False, 'default': None}, + cache_security_groups={'required': False, 'default': [default], 'type': 'list'}, security_group_ids={'required': False, 'default': [], 'type': 'list'}, @@ -507,12 +518,21 @@ def main(): node_type = module.params['node_type'] num_nodes = module.params['num_nodes'] cache_port = module.params['cache_port'] + cache_subnet_group = module.params['cache_subnet_group'] cache_security_groups = module.params['cache_security_groups'] security_group_ids = module.params['security_group_ids'] zone = module.params['zone'] wait = module.params['wait'] hard_modify = module.params['hard_modify'] + if cache_subnet_group and cache_security_groups == [default]: + cache_security_groups = [] + if cache_subnet_group and cache_security_groups: + module.fail_json(msg="Can't specify both cache_subnet_group and cache_security_groups") + + if cache_security_groups == [default]: + cache_security_groups = ['default'] + if state == 'present' and not num_nodes: module.fail_json(msg="'num_nodes' is a required parameter. Please specify num_nodes > 0") @@ -522,6 +542,7 @@ def main(): elasticache_manager = ElastiCacheManager(module, name, engine, cache_engine_version, node_type, num_nodes, cache_port, + cache_subnet_group, cache_security_groups, security_group_ids, zone, wait, hard_modify, aws_access_key,