mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[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.
This commit is contained in:
parent
cb01f33d1e
commit
f219d6b96d
1 changed files with 9 additions and 3 deletions
|
@ -806,6 +806,8 @@ def create_autoscaling_group(connection, module):
|
|||
launch_configs = describe_launch_configurations(connection, launch_config_name)
|
||||
if len(launch_configs['LaunchConfigurations']) == 0:
|
||||
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(
|
||||
AutoScalingGroupName=group_name,
|
||||
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))
|
||||
|
||||
# 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']
|
||||
min_size = min_size if min_size is not None else as_group['MinSize']
|
||||
max_size = max_size if max_size is not None else as_group['MaxSize']
|
||||
# check if min_size/max_size/desired capacity have been specified and if not use ASG values
|
||||
if min_size is None:
|
||||
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_configs = describe_launch_configurations(connection, launch_config_name)
|
||||
|
|
Loading…
Reference in a new issue