Repository: cloudtools/troposphere

Issue:
AutoScalingRollingUpdate with 'If' Aws Helper Condition fail during validate
Hi, in autoscalinggroup  UpdatePolicy if i have a AutoScalingRollingUpdate with a IF AWS Helper Condition it fails during validate with:
##
AttributeError: 'If' object has no attribute 'MinInstancesInService'
##

Example code:
##
                AutoScalingRollingUpdate=If(
                    'RollingUpdate',
                    pol.AutoScalingRollingUpdate(
                        MaxBatchSize=get_mapped_value('RollingUpdateMaxBatchSize'),
                        MinInstancesInService=get_mapped_value('RollingUpdateMinInstancesInService'),
                        MinSuccessfulInstancesPercent=get_mapped_value('RollingUpdateMinSuccessfulInstancesPercent'),
                        PauseTime=get_mapped_value('RollingUpdatePauseTime'),
                        SuspendProcesses=[
                            'HealthCheck',
                            'ReplaceUnhealthy',
                            'AlarmNotification',
                            'ScheduledActions'
                        ],
                        WaitOnResourceSignals=True
                    ),
                    Ref('AWS::NoValue')
                ),
##

To solve issue, in troposphere/autoscaling.py function validate should be:
```
diff --git a/troposphere/autoscaling.py b/troposphere/autoscaling.py
index cc5873f..8f7a43d 100644
--- a/troposphere/autoscaling.py
+++ b/troposphere/autoscaling.py
@@ -136,7 +136,8 @@ class AutoScalingGroup(AWSObject):
             update_policy = self.resource['UpdatePolicy']
 
             if (not isinstance(update_policy, AWSHelperFn) and
-                    'AutoScalingRollingUpdate' in update_policy.properties):
+                    'AutoScalingRollingUpdate' in update_policy.properties and
+                    not isinstance(update_policy.AutoScalingRollingUpdate, AWSHelperFn)):
                 rolling_update = update_policy.AutoScalingRollingUpdate
 
                 isMinNoCheck = isinstance(
```
##

Regards, Alberto.


Discussion:

Resolving patch:
diff --git a/troposphere/autoscaling.py b/troposphere/autoscaling.py
--- a/troposphere/autoscaling.py
+++ b/troposphere/autoscaling.py
@@ -137,23 +137,26 @@ def validate(self):
 
             if (not isinstance(update_policy, AWSHelperFn) and
                     'AutoScalingRollingUpdate' in update_policy.properties):
-                rolling_update = update_policy.AutoScalingRollingUpdate
-
-                isMinNoCheck = isinstance(
-                    rolling_update.MinInstancesInService,
-                    (FindInMap, Ref)
-                )
-                isMaxNoCheck = isinstance(self.MaxSize, (If, FindInMap, Ref))
-
-                if not (isMinNoCheck or isMaxNoCheck):
-                    maxCount = int(self.MaxSize)
-                    minCount = int(rolling_update.MinInstancesInService)
-
-                    if minCount >= maxCount:
-                        raise ValueError(
-                            "The UpdatePolicy attribute "
-                            "MinInstancesInService must be less than the "
-                            "autoscaling group's MaxSize")
+                if not isinstance(
+                        update_policy.AutoScalingRollingUpdate, AWSHelperFn):
+                    rolling_update = update_policy.AutoScalingRollingUpdate
+
+                    is_min_no_check = isinstance(
+                        rolling_update.MinInstancesInService,
+                        (FindInMap, Ref)
+                    )
+                    is_max_no_check = isinstance(self.MaxSize,
+                                                 (If, FindInMap, Ref))
+
+                    if not (is_min_no_check or is_max_no_check):
+                        max_count = int(self.MaxSize)
+                        min_count = int(rolling_update.MinInstancesInService)
+
+                        if min_count >= max_count:
+                            raise ValueError(
+                                "The UpdatePolicy attribute "
+                                "MinInstancesInService must be less than the "
+                                "autoscaling group's MaxSize")
 
         launch_config = self.properties.get('LaunchConfigurationName')
         instance_id = self.properties.get('InstanceId')


Test patch:
diff --git a/tests/test_asg.py b/tests/test_asg.py
--- a/tests/test_asg.py
+++ b/tests/test_asg.py
@@ -83,6 +83,30 @@ def test_helperfn_as_updatepolicy(self):
         )
         self.assertTrue(group.validate())
 
+    def test_helperfn_as_AutoScalingRollingUpdate(self):
+        update_policy = UpdatePolicy(
+            AutoScalingRollingUpdate=If(
+                'RollingUpdate',
+                AutoScalingRollingUpdate(
+                    PauseTime='PT5M',
+                    MinInstancesInService="1",
+                    MaxBatchSize='1',
+                    WaitOnResourceSignals=True
+                ),
+                Ref("AWS::NoValue"),
+            ),
+        )
+        group = AutoScalingGroup(
+            'mygroup',
+            AvailabilityZones=['eu-west-1a', 'eu-west-1b'],
+            LaunchConfigurationName="I'm a test",
+            MaxSize=If("isstage", "1", "5"),
+            MinSize="1",
+            UpdatePolicy=If("UseUpdatePolicy",
+                            update_policy, Ref("AWS::NoValue"))
+        )
+        self.assertTrue(group.validate())
+
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/tests/test_policies.py b/tests/test_policies.py
--- a/tests/test_policies.py
+++ b/tests/test_policies.py
@@ -10,7 +10,7 @@
 
 class TestCreationPolicy(unittest.TestCase):
 
-    def test_pausetime(self):
+    def test_invalid_pausetime(self):
         with self.assertRaises(ValueError):
             CreationPolicy(ResourceSignal=ResourceSignal(Count=2,
                                                          Timeout='90'))
@@ -70,7 +70,7 @@ def test_auto_scaling_creation_policy_json(self):
 
 class TestUpdatePolicy(unittest.TestCase):
 
-    def test_pausetime(self):
+    def test_invalid_pausetime(self):
         with self.assertRaises(ValueError):
             UpdatePolicy(AutoScalingRollingUpdate=AutoScalingRollingUpdate(
                 PauseTime='90'