provider/aws: fix potential panic when finding network ACL

This commit is contained in:
Mitchell Hashimoto 2015-04-22 12:39:01 +02:00
parent a27890b1a6
commit f77f77f9f8
1 changed files with 5 additions and 4 deletions

View File

@ -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)