providers/aws: only flatten cidr if they exist

fixes #87
This commit is contained in:
Jack Pearkes 2014-07-29 10:29:48 -04:00
parent 86c7aeb8a6
commit 4f2026f6c6
2 changed files with 22 additions and 1 deletions

View File

@ -111,7 +111,10 @@ func flattenIPPerms(list []ec2.IPPerm) []map[string]interface{} {
n["from_port"] = perm.FromPort
n["protocol"] = perm.Protocol
n["to_port"] = perm.ToPort
n["cidr_blocks"] = perm.SourceIPs
if len(perm.SourceIPs) > 0 {
n["cidr_blocks"] = perm.SourceIPs
}
if v := flattenSecurityGroups(perm.SourceGroups); len(v) > 0 {
n["security_groups"] = v

View File

@ -155,6 +155,24 @@ func Test_flattenIPPerms(t *testing.T) {
},
},
},
{
Input: []ec2.IPPerm{
ec2.IPPerm{
Protocol: "icmp",
FromPort: 1,
ToPort: -1,
SourceIPs: nil,
},
},
Output: []map[string]interface{}{
map[string]interface{}{
"protocol": "icmp",
"from_port": 1,
"to_port": -1,
},
},
},
}
for _, tc := range cases {