From f77f77f9f874ec1174657a25b1b4b93686a84a46 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 22 Apr 2015 12:39:01 +0200 Subject: [PATCH] provider/aws: fix potential panic when finding network ACL --- builtin/providers/aws/resource_aws_network_acl.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/providers/aws/resource_aws_network_acl.go b/builtin/providers/aws/resource_aws_network_acl.go index 867c5a242..4f1e542e5 100644 --- a/builtin/providers/aws/resource_aws_network_acl.go +++ b/builtin/providers/aws/resource_aws_network_acl.go @@ -185,7 +185,6 @@ func resourceAwsNetworkAclUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("subnet_id") { - //associate new subnet with the acl. _, n := d.GetChange("subnet_id") newSubnet := n.(string) @@ -355,9 +354,11 @@ func findNetworkAclAssociation(subnetId string, conn *ec2.EC2) (networkAclAssoci if err != nil { return nil, err } - for _, association := range resp.NetworkACLs[0].Associations { - if *association.SubnetID == subnetId { - return association, nil + if resp.NetworkACLs != nil && len(resp.NetworkACLs) > 0 { + for _, association := range resp.NetworkACLs[0].Associations { + if *association.SubnetID == subnetId { + return association, nil + } } } return nil, fmt.Errorf("could not find association for subnet %s ", subnetId)