github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/builtin/providers/google/resource_compute_target_https_proxy_test.go (about) 1 package google 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/acctest" 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func TestAccComputeTargetHttpsProxy_basic(t *testing.T) { 13 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroy, 18 Steps: []resource.TestStep{ 19 resource.TestStep{ 20 Config: testAccComputeTargetHttpsProxy_basic1, 21 Check: resource.ComposeTestCheckFunc( 22 testAccCheckComputeTargetHttpsProxyExists( 23 "google_compute_target_https_proxy.foobar"), 24 ), 25 }, 26 }, 27 }) 28 } 29 30 func TestAccComputeTargetHttpsProxy_update(t *testing.T) { 31 32 resource.Test(t, resource.TestCase{ 33 PreCheck: func() { testAccPreCheck(t) }, 34 Providers: testAccProviders, 35 CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroy, 36 Steps: []resource.TestStep{ 37 resource.TestStep{ 38 Config: testAccComputeTargetHttpsProxy_basic1, 39 Check: resource.ComposeTestCheckFunc( 40 testAccCheckComputeTargetHttpsProxyExists( 41 "google_compute_target_https_proxy.foobar"), 42 ), 43 }, 44 45 resource.TestStep{ 46 Config: testAccComputeTargetHttpsProxy_basic2, 47 Check: resource.ComposeTestCheckFunc( 48 testAccCheckComputeTargetHttpsProxyExists( 49 "google_compute_target_https_proxy.foobar"), 50 ), 51 }, 52 }, 53 }) 54 } 55 56 func testAccCheckComputeTargetHttpsProxyDestroy(s *terraform.State) error { 57 config := testAccProvider.Meta().(*Config) 58 59 for _, rs := range s.RootModule().Resources { 60 if rs.Type != "google_compute_target_https_proxy" { 61 continue 62 } 63 64 _, err := config.clientCompute.TargetHttpsProxies.Get( 65 config.Project, rs.Primary.ID).Do() 66 if err == nil { 67 return fmt.Errorf("TargetHttpsProxy still exists") 68 } 69 } 70 71 return nil 72 } 73 74 func testAccCheckComputeTargetHttpsProxyExists(n string) resource.TestCheckFunc { 75 return func(s *terraform.State) error { 76 rs, ok := s.RootModule().Resources[n] 77 if !ok { 78 return fmt.Errorf("Not found: %s", n) 79 } 80 81 if rs.Primary.ID == "" { 82 return fmt.Errorf("No ID is set") 83 } 84 85 config := testAccProvider.Meta().(*Config) 86 87 found, err := config.clientCompute.TargetHttpsProxies.Get( 88 config.Project, rs.Primary.ID).Do() 89 if err != nil { 90 return err 91 } 92 93 if found.Name != rs.Primary.ID { 94 return fmt.Errorf("TargetHttpsProxy not found") 95 } 96 97 return nil 98 } 99 } 100 101 var testAccComputeTargetHttpsProxy_basic1 = fmt.Sprintf(` 102 resource "google_compute_target_https_proxy" "foobar" { 103 description = "Resource created for Terraform acceptance testing" 104 name = "httpsproxy-test-%s" 105 url_map = "${google_compute_url_map.foobar.self_link}" 106 ssl_certificates = ["${google_compute_ssl_certificate.foobar1.self_link}"] 107 } 108 109 resource "google_compute_backend_service" "foobar" { 110 name = "httpsproxy-test-%s" 111 health_checks = ["${google_compute_http_health_check.zero.self_link}"] 112 } 113 114 resource "google_compute_http_health_check" "zero" { 115 name = "httpsproxy-test-%s" 116 request_path = "/" 117 check_interval_sec = 1 118 timeout_sec = 1 119 } 120 121 resource "google_compute_url_map" "foobar" { 122 name = "httpsproxy-test-%s" 123 default_service = "${google_compute_backend_service.foobar.self_link}" 124 host_rule { 125 hosts = ["mysite.com", "myothersite.com"] 126 path_matcher = "boop" 127 } 128 path_matcher { 129 default_service = "${google_compute_backend_service.foobar.self_link}" 130 name = "boop" 131 path_rule { 132 paths = ["/*"] 133 service = "${google_compute_backend_service.foobar.self_link}" 134 } 135 } 136 test { 137 host = "mysite.com" 138 path = "/*" 139 service = "${google_compute_backend_service.foobar.self_link}" 140 } 141 } 142 143 resource "google_compute_ssl_certificate" "foobar1" { 144 name = "httpsproxy-test-%s" 145 description = "very descriptive" 146 private_key = "${file("test-fixtures/ssl_cert/test.key")}" 147 certificate = "${file("test-fixtures/ssl_cert/test.crt")}" 148 } 149 150 resource "google_compute_ssl_certificate" "foobar2" { 151 name = "httpsproxy-test-%s" 152 description = "very descriptive" 153 private_key = "${file("test-fixtures/ssl_cert/test.key")}" 154 certificate = "${file("test-fixtures/ssl_cert/test.crt")}" 155 } 156 `, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), 157 acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) 158 159 var testAccComputeTargetHttpsProxy_basic2 = fmt.Sprintf(` 160 resource "google_compute_target_https_proxy" "foobar" { 161 description = "Resource created for Terraform acceptance testing" 162 name = "httpsproxy-test-%s" 163 url_map = "${google_compute_url_map.foobar.self_link}" 164 ssl_certificates = ["${google_compute_ssl_certificate.foobar1.self_link}"] 165 } 166 167 resource "google_compute_backend_service" "foobar" { 168 name = "httpsproxy-test-%s" 169 health_checks = ["${google_compute_http_health_check.zero.self_link}"] 170 } 171 172 resource "google_compute_http_health_check" "zero" { 173 name = "httpsproxy-test-%s" 174 request_path = "/" 175 check_interval_sec = 1 176 timeout_sec = 1 177 } 178 179 resource "google_compute_url_map" "foobar" { 180 name = "httpsproxy-test-%s" 181 default_service = "${google_compute_backend_service.foobar.self_link}" 182 host_rule { 183 hosts = ["mysite.com", "myothersite.com"] 184 path_matcher = "boop" 185 } 186 path_matcher { 187 default_service = "${google_compute_backend_service.foobar.self_link}" 188 name = "boop" 189 path_rule { 190 paths = ["/*"] 191 service = "${google_compute_backend_service.foobar.self_link}" 192 } 193 } 194 test { 195 host = "mysite.com" 196 path = "/*" 197 service = "${google_compute_backend_service.foobar.self_link}" 198 } 199 } 200 201 resource "google_compute_ssl_certificate" "foobar1" { 202 name = "httpsproxy-test-%s" 203 description = "very descriptive" 204 private_key = "${file("test-fixtures/ssl_cert/test.key")}" 205 certificate = "${file("test-fixtures/ssl_cert/test.crt")}" 206 } 207 208 resource "google_compute_ssl_certificate" "foobar2" { 209 name = "httpsproxy-test-%s" 210 description = "very descriptive" 211 private_key = "${file("test-fixtures/ssl_cert/test.key")}" 212 certificate = "${file("test-fixtures/ssl_cert/test.crt")}" 213 } 214 `, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), 215 acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))