2015-11-01 15:39:08 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-11-01 15:39:08 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccComputeTargetHttpProxy_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
2015-11-01 15:39:08 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
|
2015-11-01 15:39:08 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeTargetHttpProxyExists(
|
|
|
|
"google_compute_target_http_proxy.foobar"),
|
|
|
|
),
|
|
|
|
},
|
2018-01-03 14:26:55 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_target_http_proxy.foobar",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2015-11-01 15:39:08 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccComputeTargetHttpProxy_update(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
target := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
backend := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
hc := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
urlmap1 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
|
|
|
urlmap2 := fmt.Sprintf("thttp-test-%s", acctest.RandString(10))
|
2015-11-01 15:39:08 +00:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeTargetHttpProxyDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2),
|
2015-11-01 15:39:08 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeTargetHttpProxyExists(
|
|
|
|
"google_compute_target_http_proxy.foobar"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
|
|
|
|
resource.TestStep{
|
2016-01-06 00:49:06 +00:00
|
|
|
Config: testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2),
|
2015-11-01 15:39:08 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeTargetHttpProxyExists(
|
|
|
|
"google_compute_target_http_proxy.foobar"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeTargetHttpProxyExists(n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
found, err := config.clientCompute.TargetHttpProxies.Get(
|
|
|
|
config.Project, rs.Primary.ID).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if found.Name != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("TargetHttpProxy not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeTargetHttpProxy_basic1(target, backend, hc, urlmap1, urlmap2 string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_target_http_proxy" "foobar" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
|
|
|
url_map = "${google_compute_url_map.foobar1.self_link}"
|
|
|
|
}
|
2015-11-01 15:39:08 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_backend_service" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
|
|
|
}
|
2015-11-01 15:39:08 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_http_health_check" "zero" {
|
|
|
|
name = "%s"
|
|
|
|
request_path = "/"
|
|
|
|
check_interval_sec = 1
|
|
|
|
timeout_sec = 1
|
2015-11-01 15:39:08 +00:00
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
|
|
|
|
resource "google_compute_url_map" "foobar1" {
|
|
|
|
name = "%s"
|
2015-11-01 15:39:08 +00:00
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2015-11-01 15:39:08 +00:00
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_url_map" "foobar2" {
|
|
|
|
name = "%s"
|
2015-11-01 15:39:08 +00:00
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2015-11-01 15:39:08 +00:00
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
`, target, backend, hc, urlmap1, urlmap2)
|
2015-11-01 15:39:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
func testAccComputeTargetHttpProxy_basic2(target, backend, hc, urlmap1, urlmap2 string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_target_http_proxy" "foobar" {
|
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
|
|
|
url_map = "${google_compute_url_map.foobar2.self_link}"
|
|
|
|
}
|
2015-11-01 15:39:08 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_backend_service" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
|
|
|
}
|
2015-11-01 15:39:08 +00:00
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_http_health_check" "zero" {
|
|
|
|
name = "%s"
|
|
|
|
request_path = "/"
|
|
|
|
check_interval_sec = 1
|
|
|
|
timeout_sec = 1
|
2015-11-01 15:39:08 +00:00
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
|
|
|
|
resource "google_compute_url_map" "foobar1" {
|
|
|
|
name = "%s"
|
2015-11-01 15:39:08 +00:00
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2015-11-01 15:39:08 +00:00
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
resource "google_compute_url_map" "foobar2" {
|
|
|
|
name = "%s"
|
2015-11-01 15:39:08 +00:00
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
|
|
|
default_service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2015-11-01 15:39:08 +00:00
|
|
|
service = "${google_compute_backend_service.foobar.self_link}"
|
|
|
|
}
|
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
`, target, backend, hc, urlmap1, urlmap2)
|
2015-11-01 15:39:08 +00:00
|
|
|
}
|