From bd67c6756a8702f997b5cd2b7847185b3d1007cd Mon Sep 17 00:00:00 2001 From: David Hummel Date: Fri, 20 Dec 2013 16:06:55 -0500 Subject: [PATCH 1/2] Add rule group_name parameter whose value can reference containing group name. --- library/cloud/ec2_group | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/library/cloud/ec2_group b/library/cloud/ec2_group index c325c1ce301..85005224f6f 100644 --- a/library/cloud/ec2_group +++ b/library/cloud/ec2_group @@ -87,7 +87,10 @@ EXAMPLES = ''' - proto: udp from_port: 10051 to_port: 10051 - group_id: abcdef + group_id: sg-12345678 + - proto: all + # the containing group name may be specified here + group_name: example ''' try: @@ -152,6 +155,7 @@ def main(): groups = {} for curGroup in ec2.get_all_security_groups(): groups[curGroup.id] = curGroup + groups[curGroup.name] = curGroup if curGroup.name == name and curGroup.vpc_id == vpc_id: group = curGroup @@ -203,11 +207,22 @@ def main(): if rules: for rule in rules: group_id = None + group_name = None ip = None if 'group_id' in rule and 'cidr_ip' in rule: module.fail_json(msg="Specify group_id OR cidr_ip, not both") + elif 'group_id' in rule and 'group_name' in rule: + module.fail_json(msg="Specify group_id OR group_name, not both") elif 'group_id' in rule: group_id = rule['group_id'] + elif 'group_name' in rule: + group_name = rule['group_name'] + if group_name in groups: + group_id = groups[group_name].id + elif group_name == name: + group_id = group.id + groups[group_id] = group + groups[group_name] = group elif 'cidr_ip' in rule: ip = rule['cidr_ip'] From c5433d9742e63159be13050e01449d2c40571b5d Mon Sep 17 00:00:00 2001 From: David Hummel Date: Mon, 23 Dec 2013 15:57:47 -0500 Subject: [PATCH 2/2] Check for group_name and cidr_ip. --- library/cloud/ec2_group | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/cloud/ec2_group b/library/cloud/ec2_group index 85005224f6f..63850efb789 100644 --- a/library/cloud/ec2_group +++ b/library/cloud/ec2_group @@ -211,6 +211,8 @@ def main(): ip = None if 'group_id' in rule and 'cidr_ip' in rule: module.fail_json(msg="Specify group_id OR cidr_ip, not both") + elif 'group_name' in rule and 'cidr_ip' in rule: + module.fail_json(msg="Specify group_name OR cidr_ip, not both") elif 'group_id' in rule and 'group_name' in rule: module.fail_json(msg="Specify group_id OR group_name, not both") elif 'group_id' in rule: