github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/google/resource_compute_ssl_certificate_test.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 ) 10 11 func TestAccComputeSslCertificate_basic(t *testing.T) { 12 resource.Test(t, resource.TestCase{ 13 PreCheck: func() { testAccPreCheck(t) }, 14 Providers: testAccProviders, 15 CheckDestroy: testAccCheckComputeSslCertificateDestroy, 16 Steps: []resource.TestStep{ 17 resource.TestStep{ 18 Config: testAccComputeSslCertificate_basic, 19 Check: resource.ComposeTestCheckFunc( 20 testAccCheckComputeSslCertificateExists( 21 "google_compute_ssl_certificate.foobar"), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 func testAccCheckComputeSslCertificateDestroy(s *terraform.State) error { 29 config := testAccProvider.Meta().(*Config) 30 31 for _, rs := range s.RootModule().Resources { 32 if rs.Type != "google_compute_ssl_certificate" { 33 continue 34 } 35 36 _, err := config.clientCompute.SslCertificates.Get( 37 config.Project, rs.Primary.ID).Do() 38 if err == nil { 39 return fmt.Errorf("SslCertificate still exists") 40 } 41 } 42 43 return nil 44 } 45 46 func testAccCheckComputeSslCertificateExists(n string) resource.TestCheckFunc { 47 return func(s *terraform.State) error { 48 rs, ok := s.RootModule().Resources[n] 49 if !ok { 50 return fmt.Errorf("Not found: %s", n) 51 } 52 53 if rs.Primary.ID == "" { 54 return fmt.Errorf("No ID is set") 55 } 56 57 config := testAccProvider.Meta().(*Config) 58 59 found, err := config.clientCompute.SslCertificates.Get( 60 config.Project, rs.Primary.ID).Do() 61 if err != nil { 62 return err 63 } 64 65 if found.Name != rs.Primary.ID { 66 return fmt.Errorf("Certificate not found") 67 } 68 69 return nil 70 } 71 } 72 73 const testAccComputeSslCertificate_basic = ` 74 resource "google_compute_ssl_certificate" "foobar" { 75 name = "terraform-test" 76 description = "very descriptive" 77 private_key = "${file("test-fixtures/ssl_cert/test.key")}" 78 certificate = "${file("test-fixtures/ssl_cert/test.crt")}" 79 } 80 `