[cloud] EC2_ASG Set desired capacity to min_size if no instances exist (#30987)

* Set desired capacity to min_size if no instances exist

* Improve readability of if/then clause

* Only update null desired_capacity to min_size on initial create

Any future updates to the ASG will be able to reference the existing
capacity.
pull/23568/merge
Bradford Dabbs 7 years ago committed by Ryan Brown
parent cb01f33d1e
commit f219d6b96d

@ -806,6 +806,8 @@ def create_autoscaling_group(connection, module):
launch_configs = describe_launch_configurations(connection, launch_config_name) launch_configs = describe_launch_configurations(connection, launch_config_name)
if len(launch_configs['LaunchConfigurations']) == 0: if len(launch_configs['LaunchConfigurations']) == 0:
module.fail_json(msg="No launch config found with name %s" % launch_config_name) module.fail_json(msg="No launch config found with name %s" % launch_config_name)
if desired_capacity is None:
desired_capacity = min_size
ag = dict( ag = dict(
AutoScalingGroupName=group_name, AutoScalingGroupName=group_name,
LaunchConfigurationName=launch_configs['LaunchConfigurations'][0]['LaunchConfigurationName'], LaunchConfigurationName=launch_configs['LaunchConfigurations'][0]['LaunchConfigurationName'],
@ -952,9 +954,13 @@ def create_autoscaling_group(connection, module):
attach_lb_target_groups(connection, group_name, list(tgs_to_attach)) attach_lb_target_groups(connection, group_name, list(tgs_to_attach))
# check for attributes that aren't required for updating an existing ASG # check for attributes that aren't required for updating an existing ASG
desired_capacity = desired_capacity if desired_capacity is not None else as_group['DesiredCapacity'] # check if min_size/max_size/desired capacity have been specified and if not use ASG values
min_size = min_size if min_size is not None else as_group['MinSize'] if min_size is None:
max_size = max_size if max_size is not None else as_group['MaxSize'] min_size = as_group['MinSize']
if max_size is None:
max_size = as_group['MaxSize']
if desired_capacity is None:
desired_capacity = as_group['DesiredCapacity']
launch_config_name = launch_config_name or as_group['LaunchConfigurationName'] launch_config_name = launch_config_name or as_group['LaunchConfigurationName']
launch_configs = describe_launch_configurations(connection, launch_config_name) launch_configs = describe_launch_configurations(connection, launch_config_name)

Loading…
Cancel
Save