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