Repository: zalando-stups/senza

Issue:
Senza ignores "SpotPrice" property on auto scaling group
```
      InstanceType: m4.xlarge
      SpotPrice: 0.250
```

According to cloudformation specs this will create an ASG with spot instances.

Discussion:

Patch:
diff --git a/senza/components/auto_scaling_group.py b/senza/components/auto_scaling_group.py
index ebffa4b..17d8974 100644
--- a/senza/components/auto_scaling_group.py
+++ b/senza/components/auto_scaling_group.py
@@ -20,11 +20,9 @@ def component_auto_scaling_group(definition, configuration, args, info, force, a
         }
     }
 
-    if 'BlockDeviceMappings' in configuration:
-        definition['Resources'][config_name]['Properties']['BlockDeviceMappings'] = configuration['BlockDeviceMappings']
-
-    if "IamInstanceProfile" in configuration:
-        definition["Resources"][config_name]["Properties"]["IamInstanceProfile"] = configuration["IamInstanceProfile"]
+    for key in set(["BlockDeviceMappings", "IamInstanceProfile", "SpotPrice"]):
+        if key in configuration:
+            definition['Resources'][config_name]['Properties'][key] = configuration[key]
 
     if 'IamRoles' in configuration:
         logical_id = configuration['Name'] + 'InstanceProfile'


Test patch:
diff --git a/tests/test_components.py b/tests/test_components.py
index 7989398..1191bae 100644
--- a/tests/test_components.py
+++ b/tests/test_components.py
@@ -504,6 +504,33 @@ def test_component_auto_scaling_group_configurable_properties():
     assert result["Resources"]["FooCPUAlarmHigh"]["Properties"]["EvaluationPeriods"] == "1"
     assert result["Resources"]["FooCPUAlarmLow"]["Properties"]["AlarmDescription"] == expected_desc
 
+def test_component_auto_scaling_group_configurable_properties():
+    definition = {"Resources": {}}
+    configuration = {
+        'Name': 'Foo',
+        'InstanceType': 't2.micro',
+        'Image': 'foo',
+        'SpotPrice': 0.250
+    }
+
+    args = MagicMock()
+    args.region = "foo"
+
+    info = {
+        'StackName': 'FooStack',
+        'StackVersion': 'FooVersion'
+    }
+
+    result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
+
+    assert result["Resources"]["FooConfig"]["Properties"]["SpotPrice"] == 0.250
+
+    del configuration["SpotPrice"]
+
+    result = component_auto_scaling_group(definition, configuration, args, info, False, MagicMock())
+
+    assert "SpotPrice" not in result["Resources"]["FooConfig"]["Properties"]
+
 
 def test_component_auto_scaling_group_metric_type():
     definition = {"Resources": {}}