From 03ee059da3f3584c80eeb55aac9d9fd657200ec4 Mon Sep 17 00:00:00 2001 From: Christopher Tiwald Date: Tue, 5 May 2015 14:44:05 -0400 Subject: [PATCH] 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. --- .../providers/aws/resource_aws_network_acl.go | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_network_acl.go b/builtin/providers/aws/resource_aws_network_acl.go index 7e33470963..c166aa6d84 100644 --- a/builtin/providers/aws/resource_aws_network_acl.go +++ b/builtin/providers/aws/resource_aws_network_acl.go @@ -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 +}