AWS EC2 ASG - Replace ELBs correctly and remove existing ELBs when specified as an empty list (#27830)
* fixes for edge cases - load_balancers has not been specified - don't want to delete existing elbs, wanted elbs aren't a superset of has_elbs (eg. 1 elb existing, adding another), specifying load_balancers: [] to delete existing elbs
This commit is contained in:
parent
14186af558
commit
82765637b9
1 changed files with 3 additions and 2 deletions
|
@ -800,6 +800,7 @@ def create_autoscaling_group(connection, module):
|
|||
|
||||
# Update load balancers if they are specified and one or more already exists
|
||||
elif as_group['LoadBalancerNames']:
|
||||
change_load_balancers = load_balancers is not None
|
||||
# Get differences
|
||||
if not load_balancers:
|
||||
load_balancers = list()
|
||||
|
@ -807,7 +808,7 @@ def create_autoscaling_group(connection, module):
|
|||
|
||||
has_elbs = set(as_group['LoadBalancerNames'])
|
||||
# check if all requested are already existing
|
||||
if has_elbs.issuperset(wanted_elbs):
|
||||
if has_elbs - wanted_elbs and change_load_balancers:
|
||||
# if wanted contains less than existing, then we need to delete some
|
||||
elbs_to_detach = has_elbs.difference(wanted_elbs)
|
||||
if elbs_to_detach:
|
||||
|
@ -816,7 +817,7 @@ def create_autoscaling_group(connection, module):
|
|||
AutoScalingGroupName=group_name,
|
||||
LoadBalancerNames=list(elbs_to_detach)
|
||||
)
|
||||
if wanted_elbs.issuperset(has_elbs):
|
||||
if wanted_elbs - has_elbs:
|
||||
# if has contains less than wanted, then we need to add some
|
||||
elbs_to_attach = wanted_elbs.difference(has_elbs)
|
||||
if elbs_to_attach:
|
||||
|
|
Loading…
Reference in a new issue