2015-10-30 20:34:14 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-04-25 19:46:18 +00:00
|
|
|
"regexp"
|
2015-10-30 20:34:14 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-01-05 21:47:10 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2015-10-30 20:34:14 +00:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
)
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
func TestAccComputeGlobalForwardingRule_updateTarget(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-01-06 00:49:06 +00:00
|
|
|
fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
2019-04-25 19:46:18 +00:00
|
|
|
proxy := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
proxyUpdated := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
2016-01-06 00:49:06 +00:00
|
|
|
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
|
2015-10-30 20:34:14 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
Config: testAccComputeGlobalForwardingRule_httpProxy(fr, "proxy", proxy, proxyUpdated, backend, hc, urlmap),
|
2015-10-30 20:34:14 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2019-04-25 19:46:18 +00:00
|
|
|
resource.TestMatchResourceAttr(
|
|
|
|
"google_compute_global_forwarding_rule.forwarding_rule", "target", regexp.MustCompile(proxy+"$")),
|
2015-10-30 20:34:14 +00:00
|
|
|
),
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
|
2017-12-19 20:43:30 +00:00
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
Config: testAccComputeGlobalForwardingRule_httpProxy(fr, "proxy2", proxy, proxyUpdated, backend, hc, urlmap),
|
2015-10-30 20:34:14 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2019-04-25 19:46:18 +00:00
|
|
|
resource.TestMatchResourceAttr(
|
|
|
|
"google_compute_global_forwarding_rule.forwarding_rule", "target", regexp.MustCompile(proxyUpdated+"$")),
|
2015-10-30 20:34:14 +00:00
|
|
|
),
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2015-10-30 20:34:14 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-08-04 17:15:51 +00:00
|
|
|
func TestAccComputeGlobalForwardingRule_ipv6(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-04 17:15:51 +00:00
|
|
|
fr := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
2019-04-25 19:46:18 +00:00
|
|
|
proxy := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
2017-08-04 17:15:51 +00:00
|
|
|
backend := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
hc := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
urlmap := fmt.Sprintf("forwardrule-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
Config: testAccComputeGlobalForwardingRule_ipv6(fr, proxy, backend, hc, urlmap),
|
2017-08-04 17:15:51 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
2019-04-25 19:46:18 +00:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_compute_global_forwarding_rule.forwarding_rule", "ip_version", "IPV6"),
|
2017-08-04 17:15:51 +00:00
|
|
|
),
|
|
|
|
},
|
2018-12-14 20:51:11 +00:00
|
|
|
{
|
2019-04-25 19:46:18 +00:00
|
|
|
ResourceName: "google_compute_global_forwarding_rule.forwarding_rule",
|
2017-12-19 20:43:30 +00:00
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-08-04 17:15:51 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
func testAccComputeGlobalForwardingRule_httpProxy(fr, targetProxy, proxy, proxy2, backend, hc, urlmap string) string {
|
2016-01-06 00:49:06 +00:00
|
|
|
return fmt.Sprintf(`
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
|
2016-01-06 00:49:06 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_protocol = "TCP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80"
|
2019-04-25 19:46:18 +00:00
|
|
|
target = "${google_compute_target_http_proxy.%s.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-10-30 20:34:14 +00:00
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_target_http_proxy" "proxy" {
|
2016-01-06 00:49:06 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
name = "%s"
|
2019-04-25 19:46:18 +00:00
|
|
|
url_map = "${google_compute_url_map.url_map.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-10-30 20:34:14 +00:00
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_target_http_proxy" "proxy2" {
|
2016-01-06 00:49:06 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
2017-08-04 17:15:51 +00:00
|
|
|
name = "%s"
|
2019-04-25 19:46:18 +00:00
|
|
|
url_map = "${google_compute_url_map.url_map.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_backend_service" "backend" {
|
2017-08-04 17:15:51 +00:00
|
|
|
name = "%s"
|
|
|
|
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_http_health_check" "zero" {
|
|
|
|
name = "%s"
|
|
|
|
request_path = "/"
|
|
|
|
check_interval_sec = 1
|
|
|
|
timeout_sec = 1
|
|
|
|
}
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_url_map" "url_map" {
|
2017-08-04 17:15:51 +00:00
|
|
|
name = "%s"
|
2019-04-25 19:46:18 +00:00
|
|
|
default_service = "${google_compute_backend_service.backend.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
2019-04-25 19:46:18 +00:00
|
|
|
default_service = "${google_compute_backend_service.backend.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
2019-04-25 19:46:18 +00:00
|
|
|
service = "${google_compute_backend_service.backend.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2019-04-25 19:46:18 +00:00
|
|
|
service = "${google_compute_backend_service.backend.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
}
|
2019-04-25 19:46:18 +00:00
|
|
|
}`, fr, targetProxy, proxy, proxy2, backend, hc, urlmap)
|
2017-08-04 17:15:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
func testAccComputeGlobalForwardingRule_ipv6(fr, proxy, backend, hc, urlmap string) string {
|
2017-08-04 17:15:51 +00:00
|
|
|
return fmt.Sprintf(`
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_global_forwarding_rule" "forwarding_rule" {
|
2017-08-04 17:15:51 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
|
|
|
ip_protocol = "TCP"
|
|
|
|
name = "%s"
|
|
|
|
port_range = "80"
|
2019-04-25 19:46:18 +00:00
|
|
|
target = "${google_compute_target_http_proxy.proxy.self_link}"
|
2017-08-04 17:15:51 +00:00
|
|
|
ip_version = "IPV6"
|
|
|
|
}
|
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_target_http_proxy" "proxy" {
|
2017-08-04 17:15:51 +00:00
|
|
|
description = "Resource created for Terraform acceptance testing"
|
2016-01-06 00:49:06 +00:00
|
|
|
name = "%s"
|
2019-04-25 19:46:18 +00:00
|
|
|
url_map = "${google_compute_url_map.urlmap.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
2015-10-30 20:34:14 +00:00
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_backend_service" "backend" {
|
2016-01-06 00:49:06 +00:00
|
|
|
name = "%s"
|
|
|
|
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
|
|
|
|
}
|
2015-10-30 20:34:14 +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-10-30 20:34:14 +00:00
|
|
|
}
|
2016-01-06 00:49:06 +00:00
|
|
|
|
2019-04-25 19:46:18 +00:00
|
|
|
resource "google_compute_url_map" "urlmap" {
|
2016-01-06 00:49:06 +00:00
|
|
|
name = "%s"
|
2019-04-25 19:46:18 +00:00
|
|
|
default_service = "${google_compute_backend_service.backend.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
host_rule {
|
|
|
|
hosts = ["mysite.com", "myothersite.com"]
|
|
|
|
path_matcher = "boop"
|
|
|
|
}
|
|
|
|
path_matcher {
|
2019-04-25 19:46:18 +00:00
|
|
|
default_service = "${google_compute_backend_service.backend.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
name = "boop"
|
|
|
|
path_rule {
|
|
|
|
paths = ["/*"]
|
2019-04-25 19:46:18 +00:00
|
|
|
service = "${google_compute_backend_service.backend.self_link}"
|
2016-01-06 00:49:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
test {
|
|
|
|
host = "mysite.com"
|
|
|
|
path = "/*"
|
2019-04-25 19:46:18 +00:00
|
|
|
service = "${google_compute_backend_service.backend.self_link}"
|
2015-10-30 20:34:14 +00:00
|
|
|
}
|
2019-04-25 19:46:18 +00:00
|
|
|
}`, fr, proxy, backend, hc, urlmap)
|
2015-10-30 20:34:14 +00:00
|
|
|
}
|