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