provider/aws: allow int for network acl entry [GH-1435]

This commit is contained in:
Mitchell Hashimoto 2015-04-22 12:35:23 +02:00
parent a27890b1a6
commit 19b3fa1a76
2 changed files with 27 additions and 17 deletions

View File

@ -13,11 +13,15 @@ func expandNetworkAclEntries(configured []interface{}, entryType string) ([]*ec2
for _, eRaw := range configured {
data := eRaw.(map[string]interface{})
protocol := data["protocol"].(string)
_, ok := protocolIntegers()[protocol]
if !ok {
return nil, fmt.Errorf("Invalid Protocol %s for rule %#v", protocol, data)
p, err := strconv.Atoi(protocol)
if err != nil {
var ok bool
p, ok = protocolIntegers()[protocol]
if !ok {
return nil, fmt.Errorf("Invalid Protocol %s for rule %#v", protocol, data)
}
}
p := extractProtocolInteger(data["protocol"].(string))
e := &ec2.NetworkACLEntry{
Protocol: aws.String(strconv.Itoa(p)),
PortRange: &ec2.PortRange{
@ -52,19 +56,6 @@ func flattenNetworkAclEntries(list []*ec2.NetworkACLEntry) []map[string]interfac
}
func extractProtocolInteger(protocol string) int {
return protocolIntegers()[protocol]
}
func extractProtocolString(protocol int) string {
for key, value := range protocolIntegers() {
if value == protocol {
return key
}
}
return ""
}
func protocolIntegers() map[string]int {
var protocolIntegers = make(map[string]int)
protocolIntegers = map[string]int{

View File

@ -26,6 +26,14 @@ func Test_expandNetworkACLEntry(t *testing.T) {
"action": "deny",
"rule_no": 2,
},
map[string]interface{}{
"protocol": "-1",
"from_port": 443,
"to_port": 443,
"cidr_block": "0.0.0.0/0",
"action": "deny",
"rule_no": 2,
},
}
expanded, _ := expandNetworkAclEntries(input, "egress")
@ -52,6 +60,17 @@ func Test_expandNetworkACLEntry(t *testing.T) {
CIDRBlock: aws.String("0.0.0.0/0"),
Egress: aws.Boolean(true),
},
&ec2.NetworkACLEntry{
Protocol: aws.String("-1"),
PortRange: &ec2.PortRange{
From: aws.Long(443),
To: aws.Long(443),
},
RuleAction: aws.String("deny"),
RuleNumber: aws.Long(2),
CIDRBlock: aws.String("0.0.0.0/0"),
Egress: aws.Boolean(true),
},
}
if !reflect.DeepEqual(expanded, expected) {