github.com/mhlias/terraform@v0.6.12-0.20161118140322-a5d6410b912a/builtin/providers/aws/resource_aws_dc_intra_virtual_interface_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/aws/aws-sdk-go/aws" 9 "github.com/aws/aws-sdk-go/aws/awserr" 10 "github.com/aws/aws-sdk-go/service/directconnect" 11 "github.com/hashicorp/terraform/helper/resource" 12 "github.com/hashicorp/terraform/terraform" 13 ) 14 15 func TestAccAwsDcIntraVirtualInterface_basic(t *testing.T) { 16 var virtualIF directconnect.VirtualInterface 17 18 resource.Test(t, resource.TestCase{ 19 PreCheck: func() { testAccPreCheck(t) }, 20 Providers: testAccProviders, 21 CheckDestroy: testAccCheckDCIntraVirtualInterfaceDestroy, 22 Steps: []resource.TestStep{ 23 resource.TestStep{ 24 Config: testAccDCVirtualInterfaceConfig, 25 Check: resource.ComposeTestCheckFunc( 26 testAccCheckDCIntraVirtualInterfaceExists("aws_dc_intra_virtual_interface.virtualinterface", &virtualIF), 27 ), 28 }, 29 }, 30 }) 31 } 32 33 func testAccCheckDCIntraVirtualInterfaceDestroy(s *terraform.State) error { 34 conn := testAccProvider.Meta().(*AWSClient).dcconn 35 36 for _, rs := range s.RootModule().Resources { 37 if rs.Type != "aws_dc_intra_virtual_interface" { 38 continue 39 } 40 41 // Try to find the resource 42 resp, err := conn.DescribeVirtualInterfaces(&directconnect.DescribeVirtualInterfacesInput{ 43 VirtualInterfaceId: aws.String(rs.Primary.ID), 44 }) 45 if err == nil { 46 if len(resp.VirtualInterfaces) > 0 && strings.ToLower(*resp.VirtualInterfaces[0].VirtualInterfaceState) != "deleted" { 47 return fmt.Errorf("still exists") 48 } 49 50 return nil 51 } 52 53 _, ok := err.(awserr.Error) 54 if !ok { 55 return err 56 } 57 } 58 59 return nil 60 } 61 62 func testAccCheckDCIntraVirtualInterfaceExists(n string, ng *directconnect.VirtualInterface) resource.TestCheckFunc { 63 return func(s *terraform.State) error { 64 rs, ok := s.RootModule().Resources[n] 65 if !ok { 66 return fmt.Errorf("Not found: %s", n) 67 } 68 69 if rs.Primary.ID == "" { 70 return fmt.Errorf("No ID is set") 71 } 72 73 conn := testAccProvider.Meta().(*AWSClient).dcconn 74 75 resp, err := conn.DescribeVirtualInterfaces(&directconnect.DescribeVirtualInterfacesInput{ 76 VirtualInterfaceId: aws.String(rs.Primary.ID), 77 }) 78 if err != nil { 79 return err 80 } 81 if len(resp.VirtualInterfaces) == 0 { 82 return fmt.Errorf("DCVirtualInterface not found") 83 } 84 85 *ng = *resp.VirtualInterfaces[0] 86 87 return nil 88 } 89 } 90 91 const testAccDCIntraVirtualInterfaceConfig = ` 92 93 resource "aws_dc_virtual_interface" "vif" { 94 connection_id = "dxcon-xyz" 95 virtual_interface_name = "test-vif" 96 asn = "12345" 97 vlan = "1024" 98 auth_key = "super_secret_key" 99 amazon_address = "10.0.0.45/30" 100 customer_address = "10.0.0.46/30" 101 interface_type = "private" 102 owner_id = "123456789" 103 } 104 `