aws: Write ingress/egress rules into a map so they can be set.

resourceAwsNetworkAclRead swallowed these errors resulting in rules
that never properly updated. Implement an entry-to-maplist function
that'll allow us to write something that Set knows how to read.
pull/1843/head
Christopher Tiwald 11 years ago
parent febf27a48e
commit 03ee059da3

@ -159,10 +159,15 @@ func resourceAwsNetworkAclRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("vpc_id", networkAcl.VPCID)
d.Set("ingress", ingressEntries)
d.Set("egress", egressEntries)
d.Set("tags", tagsToMapSDK(networkAcl.Tags))
if err := d.Set("ingress", networkAclEntriesToMapList(ingressEntries)); err != nil {
return err
}
if err := d.Set("egress", networkAclEntriesToMapList(egressEntries)); err != nil {
return err
}
return nil
}
@ -361,3 +366,25 @@ func findNetworkAclAssociation(subnetId string, conn *ec2.EC2) (networkAclAssoci
}
return nil, fmt.Errorf("could not find association for subnet %s ", subnetId)
}
// networkAclEntriesToMapList turns ingress/egress rules read from AWS into a list
// of maps.
func networkAclEntriesToMapList(networkAcls []*ec2.NetworkACLEntry) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(networkAcls))
for _, entry := range networkAcls {
acl := make(map[string]interface{})
acl["rule_no"] = *entry.RuleNumber
acl["action"] = *entry.RuleAction
acl["protocol"] = *entry.Protocol
acl["cidr_block"] = *entry.CIDRBlock
if entry.PortRange != nil {
acl["from_port"] = *entry.PortRange.From
acl["to_port"] = *entry.PortRange.To
}
result = append(result, acl)
}
return result
}

Loading…
Cancel
Save