Skip to content

Commit 21ef2b1

Browse files
author
Ryan Rawdon
committed
Improvement for #186 in beeswithmachineguns, to try and help with possible user experience issues. BWMG requires an id for subnets, but a name for security groups. This commit adds a fallback for security group lookup to use the provided name as an id. This could be optimized by checking if the name provided starts with sg- then using it as an ID, but hardcoding this arbitrary string check was avoided
1 parent 92c218a commit 21ef2b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

beeswithmachineguns/bees.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,19 @@ def _get_region(zone):
110110
return zone if 'gov' in zone else zone[:-1] # chop off the "d" in the "us-east-1d" to get the "Region"
111111

112112
def _get_security_group_id(connection, security_group_name, subnet):
113+
"""Takes a security group name and returns the ID. If the name cannot be found, the name will be attempted
114+
as an ID. The first group found by this name or ID will be used."""
113115
if not security_group_name:
114116
print('The bees need a security group to run under. Need to open a port from where you are to the target subnet.')
115117
return
116118

117119
security_groups = connection.get_all_security_groups(filters={'group-name': [security_group_name]})
118120

119121
if not security_groups:
120-
print('The bees need a security group to run under. The one specified was not found.')
121-
return
122+
security_groups = connection.get_all_security_groups(filters={'group-id': [security_group_name]})
123+
if not security_groups:
124+
print('The bees need a security group to run under. The one specified was not found.')
125+
return
122126

123127
return security_groups[0].id if security_groups else None
124128

0 commit comments

Comments
 (0)