Skip to content

Commit

Permalink
Adds an acceptance test for the AWS Network ACL Rules
Browse files Browse the repository at this point in the history
  • Loading branch information
stack72 committed Dec 18, 2015
1 parent c8fd2d8 commit 0a9a8ad
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions builtin/providers/aws/resource_aws_network_acl_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ func testAccCheckAWSNetworkAclRuleDestroy(s *terraform.State) error {
continue
}

rule_number := rs.Primary.Attributes["rule_number"].(int)
egress := rs.Primary.Attributes["egress"].(bool)

req := &ec2.DescribeNetworkAclsInput{
NetworkAclIds: []*string{aws.String(rs.Primary.ID)},
}
Expand All @@ -48,11 +45,7 @@ func testAccCheckAWSNetworkAclRuleDestroy(s *terraform.State) error {
if len(resp.NetworkAcls) > 0 && *resp.NetworkAcls[0].NetworkAclId == rs.Primary.ID {
networkAcl := resp.NetworkAcls[0]
if networkAcl.Entries != nil {
for _, i := range networkAcl.Entries {
if *i.RuleNumber == int64(rule_number) && *i.Egress == egress {
return fmt.Errorf("Network ACL Rule (%s) still exists.", rs.Primary.ID)
}
}
return fmt.Errorf("Network ACL Entries still exist")
}
}
}
Expand All @@ -61,7 +54,6 @@ func testAccCheckAWSNetworkAclRuleDestroy(s *terraform.State) error {
if !ok {
return err
}
// Confirm error code is what we want
if ec2err.Code() != "InvalidNetworkAclEntry.NotFound" {
return err
}
Expand All @@ -71,14 +63,37 @@ func testAccCheckAWSNetworkAclRuleDestroy(s *terraform.State) error {
}

func testAccCheckAWSNetworkAclRuleExists(n string, networkAcl *ec2.NetworkAcl) resource.TestCheckFunc {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No Security Group is set")
return fmt.Errorf("No Network ACL Id is set")
}

req := &ec2.DescribeNetworkAclsInput{
NetworkAclIds: []*string{aws.String(rs.Primary.ID)},
}
resp, err := conn.DescribeNetworkAcls(req)
if err == nil {
if len(resp.NetworkAcls) > 0 && *resp.NetworkAcls[0].NetworkAclId == rs.Primary.ID {
networkAcl := resp.NetworkAcls[0]
if networkAcl.Entries == nil {
return fmt.Errorf("No Network ACL Entries exist")
}
}
}

ec2err, ok := err.(awserr.Error)
if !ok {
return err
}
if ec2err.Code() != "InvalidNetworkAclEntry.NotFound" {
return err
}

return nil
Expand Down

0 comments on commit 0a9a8ad

Please sign in to comment.