diff --git a/aws/resource_aws_network_acl_rule.go b/aws/resource_aws_network_acl_rule.go index ac4c4a422a8..f3e686da954 100644 --- a/aws/resource_aws_network_acl_rule.go +++ b/aws/resource_aws_network_acl_rule.go @@ -269,6 +269,11 @@ func findNetworkAclRule(d *schema.ResourceData, meta interface{}) (*ec2.NetworkA log.Printf("[INFO] Describing Network Acl: %s", d.Get("network_acl_id").(string)) log.Printf("[INFO] Describing Network Acl with the Filters %#v", params) resp, err := conn.DescribeNetworkAcls(params) + + if isAWSErr(err, "InvalidNetworkAclID.NotFound", "") { + return nil, nil + } + if err != nil { return nil, fmt.Errorf("Error Finding Network Acl Rule %d: %s", d.Get("rule_number").(int), err.Error()) } diff --git a/aws/resource_aws_network_acl_rule_test.go b/aws/resource_aws_network_acl_rule_test.go index 75d35d9a682..421b5058670 100644 --- a/aws/resource_aws_network_acl_rule_test.go +++ b/aws/resource_aws_network_acl_rule_test.go @@ -34,6 +34,47 @@ func TestAccAWSNetworkAclRule_basic(t *testing.T) { }) } +func TestAccAWSNetworkAclRule_disappears(t *testing.T) { + var networkAcl ec2.NetworkAcl + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNetworkAclRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNetworkAclRuleBasicConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNetworkAclRuleExists("aws_network_acl_rule.baz", &networkAcl), + testAccCheckAWSNetworkAclRuleDelete("aws_network_acl_rule.baz"), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func TestAccAWSNetworkAclRule_disappears_NetworkAcl(t *testing.T) { + var networkAcl ec2.NetworkAcl + resourceName := "aws_network_acl.bar" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNetworkAclRuleDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNetworkAclRuleBasicConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSNetworkAclExists(resourceName, &networkAcl), + testAccCheckAWSNetworkAclDisappears(&networkAcl), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSNetworkAclRule_missingParam(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ @@ -210,26 +251,6 @@ func TestResourceAWSNetworkAclRule_validateICMPArgumentValue(t *testing.T) { } -func TestAccAWSNetworkAclRule_deleteRule(t *testing.T) { - var networkAcl ec2.NetworkAcl - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckAWSNetworkAclRuleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAWSNetworkAclRuleBasicConfig, - Check: resource.ComposeTestCheckFunc( - testAccCheckAWSNetworkAclRuleExists("aws_network_acl_rule.baz", &networkAcl), - testAccCheckAWSNetworkAclRuleDelete("aws_network_acl_rule.baz"), - ), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - func testAccCheckAWSNetworkAclRuleDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { diff --git a/aws/resource_aws_network_acl_test.go b/aws/resource_aws_network_acl_test.go index 67eb66f9f76..1e774847a45 100644 --- a/aws/resource_aws_network_acl_test.go +++ b/aws/resource_aws_network_acl_test.go @@ -121,6 +121,27 @@ func TestAccAWSNetworkAcl_importBasic(t *testing.T) { }) } +func TestAccAWSNetworkAcl_disappears(t *testing.T) { + var networkAcl ec2.NetworkAcl + resourceName := "aws_network_acl.bar" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNetworkAclDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSNetworkAclEgressNIngressConfig, + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckAWSNetworkAclExists(resourceName, &networkAcl), + testAccCheckAWSNetworkAclDisappears(&networkAcl), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSNetworkAcl_Egress_ConfigMode(t *testing.T) { var networkAcl1, networkAcl2, networkAcl3 ec2.NetworkAcl resourceName := "aws_network_acl.test" @@ -638,6 +659,20 @@ func testAccCheckAWSNetworkAclDestroy(s *terraform.State) error { return nil } +func testAccCheckAWSNetworkAclDisappears(networkAcl *ec2.NetworkAcl) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).ec2conn + + input := &ec2.DeleteNetworkAclInput{ + NetworkAclId: networkAcl.NetworkAclId, + } + + _, err := conn.DeleteNetworkAcl(input) + + return err + } +} + func testAccCheckAWSNetworkAclExists(n string, networkAcl *ec2.NetworkAcl) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n]