From 3cb234631237f0e33314ba31eb71775ec2b357f4 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Mon, 6 Oct 2014 10:49:22 -0400 Subject: [PATCH 1/2] Add `cache_subnet_group` to elasticache module According to the [docs] cache subnet groups are required inside a VPC. [docs]: http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/CacheSubnetGroups.html --- cloud/amazon/elasticache.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cloud/amazon/elasticache.py b/cloud/amazon/elasticache.py index 4e76d593cc9..cb5a790a3cf 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: @@ -484,6 +493,7 @@ 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_subnet_group={'required': False, 'default': None}, cache_security_groups={'required': False, 'default': ['default'], 'type': 'list'}, security_group_ids={'required': False, 'default': [], @@ -507,6 +517,7 @@ 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'] @@ -522,6 +533,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, From efa4d0428482998a93533ee73a77f67830ff2256 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Thu, 12 Mar 2015 15:14:14 -0400 Subject: [PATCH 2/2] Make cache_subnet_group default to empty security groups Since they can't be specified together, it seems like setting the default to no security groups is the right option. --- cloud/amazon/elasticache.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cloud/amazon/elasticache.py b/cloud/amazon/elasticache.py index cb5a790a3cf..18be34560a5 100644 --- a/cloud/amazon/elasticache.py +++ b/cloud/amazon/elasticache.py @@ -485,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}, @@ -494,7 +495,7 @@ def main(): num_nodes={'required': False, 'default': None, 'type': 'int'}, cache_port={'required': False, 'default': 11211, 'type': 'int'}, cache_subnet_group={'required': False, 'default': None}, - cache_security_groups={'required': False, 'default': ['default'], + cache_security_groups={'required': False, 'default': [default], 'type': 'list'}, security_group_ids={'required': False, 'default': [], 'type': 'list'}, @@ -524,6 +525,14 @@ def main(): 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")