Repository: cloudtools/troposphere

Issue:
Invalid json generated with SecurityGroupIngress
Ref: https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/EC2InstanceWithSecurityGroupSample.template

Invalid format generated:

``` json
"SecurityGroupIngress": [
                    {
                        "Properties": {
                            "CidrIp": "0.0.0.0/0",
                            "FromPort": "0",
                            "IpProtocol": "-1",
                            "ToPort": "65535"
                        },
                        "Type": "AWS::EC2::SecurityGroupIngress"
                    }
                ]
```

With the above template AWS will complain:

```
Encountered unsupported property Type
```

Correct format:

``` json
"SecurityGroupIngress": [
                    {
                        "CidrIp": "0.0.0.0/0",
                        "FromPort": "0",
                        "IpProtocol": "-1",
                        "ToPort": "65535"
                    }
                ]
```



Discussion:
I believe you want to use [SecurityGroupRule](https://github.com/cloudtools/troposphere/blob/master/troposphere/ec2.py#L270) like in this [example](https://github.com/cloudtools/troposphere/blob/master/examples/ELBSample.py).

thanks, `SecurityGroupRule` works like a charm.

I used `SecurityGroupIngress` as I was following this [example](https://github.com/cloudtools/troposphere/blob/ad82f96c2d9c48b5a3309757471668e490432816/examples/RedshiftClusterInVpc.py).

I also hit the same error, and was also following the same example. I guess the bug is that RedshiftClusterInVpc.py example template needs to be changed to use SecurityGroupRule.

Reopening to track that this update is needed.


Resolving patch:
diff --git a/examples/RedshiftClusterInVpc.py b/examples/RedshiftClusterInVpc.py
--- a/examples/RedshiftClusterInVpc.py
+++ b/examples/RedshiftClusterInVpc.py
@@ -6,7 +6,7 @@
 from troposphere.redshift import Cluster, ClusterParameterGroup
 from troposphere.redshift import AmazonRedshiftParameter, ClusterSubnetGroup
 from troposphere.ec2 import VPC, Subnet, InternetGateway, VPCGatewayAttachment
-from troposphere.ec2 import SecurityGroup, SecurityGroupIngress
+from troposphere.ec2 import SecurityGroup, SecurityGroupRule
 
 
 t = Template()
@@ -135,18 +135,18 @@
     InternetGatewayId=Ref("InternetGateway"),
 ))
 
-securitygroupingress1 = SecurityGroupIngress(
-    "SecurityGroupIngress1",
-    CidrIp="10.0.0.0/16",
-    FromPort="80",
-    ToPort="80",
-    IpProtocol="tcp",
-)
-
 securitygroup = t.add_resource(SecurityGroup(
     "SecurityGroup",
     GroupDescription="Security Group",
-    SecurityGroupIngress=[securitygroupingress1],
+    SecurityGroupIngress=[
+        SecurityGroupRule(
+            "SecurityGroupIngress1",
+            CidrIp="10.0.0.0/16",
+            FromPort="80",
+            ToPort="80",
+            IpProtocol="tcp",
+        )
+    ],
     VpcId=Ref("VPC"),
 ))
 


Test patch:
diff --git a/tests/examples_output/RedshiftClusterInVpc.template b/tests/examples_output/RedshiftClusterInVpc.template
--- a/tests/examples_output/RedshiftClusterInVpc.template
+++ b/tests/examples_output/RedshiftClusterInVpc.template
@@ -155,13 +155,10 @@
                 "GroupDescription": "Security Group",
                 "SecurityGroupIngress": [
                     {
-                        "Properties": {
-                            "CidrIp": "10.0.0.0/16",
-                            "FromPort": "80",
-                            "IpProtocol": "tcp",
-                            "ToPort": "80"
-                        },
-                        "Type": "AWS::EC2::SecurityGroupIngress"
+                        "CidrIp": "10.0.0.0/16",
+                        "FromPort": "80",
+                        "IpProtocol": "tcp",
+                        "ToPort": "80"
                     }
                 ],
                 "VpcId": {