From f4fb05398258ff84370d9eff3468c3786b2a9613 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Thu, 30 Jul 2015 14:10:19 -0500 Subject: [PATCH] provider/aws: Fix issue in Security Group Rules where the Security Group is not found --- builtin/providers/aws/resource_aws_security_group_rule.go | 3 +++ .../providers/aws/resource_aws_security_group_rule_test.go | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_security_group_rule.go b/builtin/providers/aws/resource_aws_security_group_rule.go index e3795c077..baff78b66 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule.go +++ b/builtin/providers/aws/resource_aws_security_group_rule.go @@ -152,7 +152,9 @@ func resourceAwsSecurityGroupRuleRead(d *schema.ResourceData, meta interface{}) sg_id := d.Get("security_group_id").(string) sg, err := findResourceSecurityGroup(conn, sg_id) if err != nil { + log.Printf("[DEBUG] Error finding Secuirty Group (%s) for Rule (%s): %s", sg_id, d.Id(), err) d.SetId("") + return nil } var rule *ec2.IPPermission @@ -256,6 +258,7 @@ func findResourceSecurityGroup(conn *ec2.EC2, id string) (*ec2.SecurityGroup, er if err != nil { return nil, err } + 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", diff --git a/builtin/providers/aws/resource_aws_security_group_rule_test.go b/builtin/providers/aws/resource_aws_security_group_rule_test.go index 053838959..8b1fa5e30 100644 --- a/builtin/providers/aws/resource_aws_security_group_rule_test.go +++ b/builtin/providers/aws/resource_aws_security_group_rule_test.go @@ -105,7 +105,7 @@ func TestIpPermissionIDHash(t *testing.T) { } } -func TestAccAWSSecurityGroupRule_Ingress(t *testing.T) { +func TestAccAWSSecurityGroupRule_Ingress_VPC(t *testing.T) { var group ec2.SecurityGroup testRuleCount := func(*terraform.State) error { @@ -142,7 +142,7 @@ func TestAccAWSSecurityGroupRule_Ingress(t *testing.T) { }) } -func TestAccAWSSecurityGroupRule_IngressClassic(t *testing.T) { +func TestAccAWSSecurityGroupRule_Ingress_Classic(t *testing.T) { var group ec2.SecurityGroup testRuleCount := func(*terraform.State) error {