github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_ip_association_test.go (about) 1 package opc 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/go-oracle-terraform/compute" 8 "github.com/hashicorp/terraform/helper/acctest" 9 "github.com/hashicorp/terraform/helper/resource" 10 "github.com/hashicorp/terraform/terraform" 11 ) 12 13 func TestAccOPCIPAssociation_Basic(t *testing.T) { 14 ri := acctest.RandInt() 15 config := fmt.Sprintf(testAccIPAssociationBasic, ri, ri) 16 17 resource.Test(t, resource.TestCase{ 18 PreCheck: func() { testAccPreCheck(t) }, 19 Providers: testAccProviders, 20 CheckDestroy: testAccOPCCheckIPAssociationDestroy, 21 Steps: []resource.TestStep{ 22 { 23 Config: config, 24 Check: resource.ComposeTestCheckFunc( 25 testAccOPCCheckIPAssociationExists, 26 ), 27 }, 28 }, 29 }) 30 } 31 32 func testAccOPCCheckIPAssociationExists(s *terraform.State) error { 33 client := testAccProvider.Meta().(*compute.Client).IPAssociations() 34 35 for _, rs := range s.RootModule().Resources { 36 if rs.Type != "opc_compute_ip_association" { 37 continue 38 } 39 40 input := compute.GetIPAssociationInput{ 41 Name: rs.Primary.Attributes["name"], 42 } 43 if _, err := client.GetIPAssociation(&input); err != nil { 44 return fmt.Errorf("Error retrieving state of IP Association %s: %s", input.Name, err) 45 } 46 } 47 48 return nil 49 } 50 51 func testAccOPCCheckIPAssociationDestroy(s *terraform.State) error { 52 client := testAccProvider.Meta().(*compute.Client).IPAssociations() 53 54 for _, rs := range s.RootModule().Resources { 55 if rs.Type != "opc_compute_ip_association" { 56 continue 57 } 58 59 input := compute.GetIPAssociationInput{ 60 Name: rs.Primary.Attributes["name"], 61 } 62 if info, err := client.GetIPAssociation(&input); err == nil { 63 return fmt.Errorf("IP Association %s still exists: %#v", input.Name, info) 64 } 65 } 66 67 return nil 68 } 69 70 var testAccIPAssociationBasic = ` 71 resource "opc_compute_instance" "test" { 72 name = "test-acc-ip-ass-instance-%d" 73 label = "testAccIPAssociationBasic" 74 shape = "oc3" 75 image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300" 76 } 77 78 resource "opc_compute_ip_reservation" "test" { 79 name = "test-acc-ip-ass-reservation-%d" 80 parent_pool = "/oracle/public/ippool" 81 permanent = true 82 } 83 84 resource "opc_compute_ip_association" "test" { 85 vcable = "${opc_compute_instance.test.vcable}" 86 parent_pool = "ipreservation:${opc_compute_ip_reservation.test.name}" 87 } 88 `