From 7fd4c2f5e1f60ff63ce6cc89fa499552bddd111d Mon Sep 17 00:00:00 2001
From: James Martin <jmartin@ansible.com>
Date: Thu, 7 Aug 2014 14:39:30 -0700
Subject: [PATCH] Implements the proper method for terminated an auto scale
 group.

---
 library/cloud/ec2_asg | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/library/cloud/ec2_asg b/library/cloud/ec2_asg
index dc2a491705c..3ed0685725c 100755
--- a/library/cloud/ec2_asg
+++ b/library/cloud/ec2_asg
@@ -283,15 +283,17 @@ def delete_autoscaling_group(connection, module):
     groups = connection.get_all_groups(names=[group_name])
     if groups:
         group = groups[0]
-        group.shutdown_instances()
-
+        group.max_size = 0
+        group.min_size = 0
+        group.desired_capacity = 0
+        group.update()
         instances = True
         while instances:
-            groups = connection.get_all_groups()
-            for group in groups:
-                if group.name == group_name:
-                    if not group.instances:
-                        instances = False
+            tmp_groups = connection.get_all_groups(names=[group_name])
+            if tmp_groups:
+                tmp_group = tmp_groups[0]
+                if not tmp_group.instances:
+                   instances = False
             time.sleep(10)
 
         group.delete()