github.com/alexissmirnov/terraform@v0.4.3-0.20150423153700-1ef9731a2f14/builtin/providers/aws/network_acl_entry.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "strconv" 6 7 "github.com/awslabs/aws-sdk-go/aws" 8 "github.com/awslabs/aws-sdk-go/service/ec2" 9 ) 10 11 func expandNetworkAclEntries(configured []interface{}, entryType string) ([]*ec2.NetworkACLEntry, error) { 12 entries := make([]*ec2.NetworkACLEntry, 0, len(configured)) 13 for _, eRaw := range configured { 14 data := eRaw.(map[string]interface{}) 15 protocol := data["protocol"].(string) 16 p, err := strconv.Atoi(protocol) 17 if err != nil { 18 var ok bool 19 p, ok = protocolIntegers()[protocol] 20 if !ok { 21 return nil, fmt.Errorf("Invalid Protocol %s for rule %#v", protocol, data) 22 } 23 } 24 25 e := &ec2.NetworkACLEntry{ 26 Protocol: aws.String(strconv.Itoa(p)), 27 PortRange: &ec2.PortRange{ 28 From: aws.Long(int64(data["from_port"].(int))), 29 To: aws.Long(int64(data["to_port"].(int))), 30 }, 31 Egress: aws.Boolean((entryType == "egress")), 32 RuleAction: aws.String(data["action"].(string)), 33 RuleNumber: aws.Long(int64(data["rule_no"].(int))), 34 CIDRBlock: aws.String(data["cidr_block"].(string)), 35 } 36 entries = append(entries, e) 37 } 38 return entries, nil 39 } 40 41 func flattenNetworkAclEntries(list []*ec2.NetworkACLEntry) []map[string]interface{} { 42 entries := make([]map[string]interface{}, 0, len(list)) 43 44 for _, entry := range list { 45 entries = append(entries, map[string]interface{}{ 46 "from_port": *entry.PortRange.From, 47 "to_port": *entry.PortRange.To, 48 "action": *entry.RuleAction, 49 "rule_no": *entry.RuleNumber, 50 "protocol": *entry.Protocol, 51 "cidr_block": *entry.CIDRBlock, 52 }) 53 } 54 55 return entries 56 57 } 58 59 func protocolIntegers() map[string]int { 60 var protocolIntegers = make(map[string]int) 61 protocolIntegers = map[string]int{ 62 "udp": 17, 63 "tcp": 6, 64 "icmp": 1, 65 "all": -1, 66 } 67 return protocolIntegers 68 }