github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/opc/resource_security_list_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 TestAccOPCSecurityList_basic(t *testing.T) { 14 ri := acctest.RandInt() 15 config := fmt.Sprintf(testAccOPCSecurityListBasic, ri) 16 17 resource.Test(t, resource.TestCase{ 18 PreCheck: func() { testAccPreCheck(t) }, 19 Providers: testAccProviders, 20 CheckDestroy: testAccCheckSecurityListDestroy, 21 Steps: []resource.TestStep{ 22 { 23 Config: config, 24 Check: testAccCheckSecurityListExists, 25 }, 26 }, 27 }) 28 } 29 30 func TestAccOPCSecurityList_complete(t *testing.T) { 31 ri := acctest.RandInt() 32 config := fmt.Sprintf(testAccOPCSecurityListComplete, ri) 33 34 resource.Test(t, resource.TestCase{ 35 PreCheck: func() { testAccPreCheck(t) }, 36 Providers: testAccProviders, 37 CheckDestroy: testAccCheckSecurityListDestroy, 38 Steps: []resource.TestStep{ 39 { 40 Config: config, 41 Check: testAccCheckSecurityListExists, 42 }, 43 }, 44 }) 45 } 46 47 func testAccCheckSecurityListExists(s *terraform.State) error { 48 client := testAccProvider.Meta().(*compute.Client).SecurityLists() 49 50 for _, rs := range s.RootModule().Resources { 51 if rs.Type != "opc_compute_security_list" { 52 continue 53 } 54 55 input := compute.GetSecurityListInput{ 56 Name: rs.Primary.Attributes["name"], 57 } 58 if _, err := client.GetSecurityList(&input); err != nil { 59 return fmt.Errorf("Error retrieving state of Security List %s: %s", input.Name, err) 60 } 61 } 62 63 return nil 64 } 65 66 func testAccCheckSecurityListDestroy(s *terraform.State) error { 67 client := testAccProvider.Meta().(*compute.Client).SecurityLists() 68 69 for _, rs := range s.RootModule().Resources { 70 if rs.Type != "opc_compute_security_list" { 71 continue 72 } 73 74 input := compute.GetSecurityListInput{ 75 Name: rs.Primary.Attributes["name"], 76 } 77 if info, err := client.GetSecurityList(&input); err == nil { 78 return fmt.Errorf("Security List %s still exists: %#v", input.Name, info) 79 } 80 } 81 82 return nil 83 } 84 85 const testAccOPCSecurityListBasic = ` 86 resource "opc_compute_security_list" "test" { 87 name = "acc-test-sec-list-%d" 88 policy = "PERMIT" 89 outbound_cidr_policy = "DENY" 90 } 91 ` 92 93 const testAccOPCSecurityListComplete = ` 94 resource "opc_compute_security_list" "test" { 95 name = "acc-test-sec-list-%d" 96 description = "Acceptance Test Security List Complete" 97 policy = "PERMIT" 98 outbound_cidr_policy = "DENY" 99 } 100 `