@ -1089,29 +1089,31 @@ def delete_autoscaling_group(connection):
del_notification_config ( connection , group_name , notification_topic )
groups = describe_autoscaling_groups ( connection , group_name )
if groups :
wait_timeout = time . time ( ) + wait_timeout
if not wait_for_instances :
delete_asg ( connection , group_name , force_delete = True )
return True
wait_timeout = time . time ( ) + wait_timeout
updated_params = dict ( AutoScalingGroupName = group_name , MinSize = 0 , MaxSize = 0 , DesiredCapacity = 0 )
update_asg ( connection , * * updated_params )
instances = True
while instances and wait_for_instances and wait_timeout > = time . time ( ) :
tmp_groups = describe_autoscaling_groups ( connection , group_name )
if tmp_groups :
tmp_group = tmp_groups [ 0 ]
if not tmp_group . get ( ' Instances ' ) :
instances = False
time . sleep ( 10 )
else :
updated_params = dict ( AutoScalingGroupName = group_name , MinSize = 0 , MaxSize = 0 , DesiredCapacity = 0 )
update_asg ( connection , * * updated_params )
instances = True
while instances and wait_for_instances and wait_timeout > = time . time ( ) :
tmp_groups = describe_autoscaling_groups ( connection , group_name )
if tmp_groups :
tmp_group = tmp_groups [ 0 ]
if not tmp_group . get ( ' Instances ' ) :
instances = False
time . sleep ( 10 )
if wait_timeout < = time . time ( ) :
# waiting took too long
module . fail_json ( msg = " Waited too long for old instances to terminate. %s " % time . asctime ( ) )
delete_asg ( connection , group_name , force_delete = False )
while describe_autoscaling_groups ( connection , group_name ) and wait_timeout > = time . time ( ) :
time . sleep ( 5 )
if wait_timeout < = time . time ( ) :
# waiting took too long
module . fail_json ( msg = " Waited too long for old instances to terminate. %s " % time . asctime ( ) )
delete_asg ( connection , group_name , force_delete = False )
while describe_autoscaling_groups ( connection , group_name ) :
time . sleep ( 5 )
module . fail_json ( msg = " Waited too long for ASG to delete. %s " % time . asctime ( ) )
return True
return False