From b0169adf028898bbf64002211b6fd3774cd80fcd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Jun 2015 16:23:24 -0700 Subject: [PATCH 1/2] providers/aws: more guards against crashy cases [GH-2308] --- .../providers/aws/resource_aws_security_group_rule.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_security_group_rule.go b/builtin/providers/aws/resource_aws_security_group_rule.go index 0ec0dfe3c..a958cdbaf 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule.go +++ b/builtin/providers/aws/resource_aws_security_group_rule.go @@ -130,10 +130,10 @@ func resourceAwsSecurityGroupRuleCreate(d *schema.ResourceData, meta interface{} if autherr != nil { if awsErr, ok := autherr.(awserr.Error); ok { if awsErr.Code() == "InvalidPermission.Duplicate" { - return fmt.Errorf(`[WARN] A duplicate Security Group rule was found. This may be -a side effect of a now-fixed Terraform issue causing two security groups with -identical attributes but different source_security_group_ids to overwrite each -other in the state. See https://github.com/hashicorp/terraform/pull/2376 for more + return fmt.Errorf(`[WARN] A duplicate Security Group rule was found. This may be +a side effect of a now-fixed Terraform issue causing two security groups with +identical attributes but different source_security_group_ids to overwrite each +other in the state. See https://github.com/hashicorp/terraform/pull/2376 for more information and instructions for recovery. Error message: %s`, awsErr.Message()) } } @@ -257,7 +257,7 @@ func findResourceSecurityGroup(conn *ec2.EC2, id string) (*ec2.SecurityGroup, er if err != nil { return nil, err } - if len(resp.SecurityGroups) != 1 { + if resp == nil || len(resp.SecurityGroups) != 1 { return nil, fmt.Errorf( "Expected to find one security group with ID %q, got: %#v", id, resp.SecurityGroups) From fef5741dedd16b496310026295efd1a476dbc82d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Jun 2015 22:48:39 -0700 Subject: [PATCH 2/2] providers/aws: fix another crash case --- builtin/providers/aws/resource_aws_security_group_rule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_security_group_rule.go b/builtin/providers/aws/resource_aws_security_group_rule.go index a958cdbaf..927030b70 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule.go +++ b/builtin/providers/aws/resource_aws_security_group_rule.go @@ -257,7 +257,7 @@ func findResourceSecurityGroup(conn *ec2.EC2, id string) (*ec2.SecurityGroup, er if err != nil { return nil, err } - if resp == nil || len(resp.SecurityGroups) != 1 { + if resp == nil || len(resp.SecurityGroups) != 1 || resp.SecurityGroups[0] == nil { return nil, fmt.Errorf( "Expected to find one security group with ID %q, got: %#v", id, resp.SecurityGroups)