Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_network_acl_rule: Remove resource from Terraform state on InvalidNetworkAclID.NotFound errors #9710

Merged
merged 1 commit into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aws/resource_aws_network_acl_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
61 changes: 41 additions & 20 deletions aws/resource_aws_network_acl_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions aws/resource_aws_network_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down