Skip to content

Commit

Permalink
Use common 'Exists' and 'Destroy' methods - hashicorp#9572.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kit Ewbank authored and ewbankkit committed Oct 4, 2019
1 parent b0434ea commit 90f397e
Showing 1 changed file with 4 additions and 63 deletions.
67 changes: 4 additions & 63 deletions aws/resource_aws_dx_hosted_transit_virtual_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,71 +166,12 @@ func testAccAwsDxHostedTransitVirtualInterface_accepterTags(t *testing.T) {
})
}

func testAccCheckAwsDxHostedTransitVirtualInterfaceDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).dxconn

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_dx_hosted_transit_virtual_interface" {
continue
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}

resp, err := conn.DescribeVirtualInterfaces(&directconnect.DescribeVirtualInterfacesInput{
VirtualInterfaceId: aws.String(rs.Primary.ID),
})
if isAWSErr(err, directconnect.ErrCodeClientException, "does not exist") {
continue
}
if err != nil {
return err
}

n := len(resp.VirtualInterfaces)
switch n {
case 0:
continue
case 1:
if aws.StringValue(resp.VirtualInterfaces[0].VirtualInterfaceState) == directconnect.VirtualInterfaceStateDeleted {
continue
}
return fmt.Errorf("still exist.")
default:
return fmt.Errorf("Found %d Direct Connect virtual interfaces for %s, expected 1", n, rs.Primary.ID)
}
}

return nil
}

func testAccCheckAwsDxHostedTransitVirtualInterfaceExists(name string, vif *directconnect.VirtualInterface) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).dxconn

rs, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}

resp, err := conn.DescribeVirtualInterfaces(&directconnect.DescribeVirtualInterfacesInput{
VirtualInterfaceId: aws.String(rs.Primary.ID),
})
if err != nil {
return err
}

if n := len(resp.VirtualInterfaces); n != 1 {
return fmt.Errorf("Found %d Direct Connect virtual interfaces for %s, expected 1", n, rs.Primary.ID)
}

*vif = *resp.VirtualInterfaces[0]
return testAccCheckDxVirtualInterfaceExists(name, vif)
}

return nil
}
func testAccCheckAwsDxHostedTransitVirtualInterfaceDestroy(s *terraform.State) error {
return testAccCheckDxVirtualInterfaceDestroy(s, "aws_dx_hosted_transit_virtual_interface")
}

func testAccDxHostedTransitVirtualInterfaceConfig_base(cid, rName string, amzAsn, bgpAsn, vlan int) string {
Expand Down

0 comments on commit 90f397e

Please sign in to comment.