mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
128 lines
3.5 KiB
Go
128 lines
3.5 KiB
Go
![]() |
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
//
|
||
|
// This file is automatically generated by Magic Modules and manual
|
||
|
// changes will be clobbered when the file is regenerated.
|
||
|
//
|
||
|
// Please read more about how to change this file in
|
||
|
// .github/CONTRIBUTING.md.
|
||
|
//
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
package google
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||
|
"github.com/hashicorp/terraform/helper/resource"
|
||
|
"github.com/hashicorp/terraform/terraform"
|
||
|
)
|
||
|
|
||
|
func TestAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(t *testing.T) {
|
||
|
t.Parallel()
|
||
|
|
||
|
context := map[string]interface{}{
|
||
|
"random_suffix": acctest.RandString(10),
|
||
|
}
|
||
|
|
||
|
resource.Test(t, resource.TestCase{
|
||
|
PreCheck: func() { testAccPreCheck(t) },
|
||
|
Providers: testAccProviders,
|
||
|
CheckDestroy: testAccCheckComputeGlobalForwardingRuleDestroy,
|
||
|
Steps: []resource.TestStep{
|
||
|
{
|
||
|
Config: testAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(context),
|
||
|
},
|
||
|
{
|
||
|
ResourceName: "google_compute_global_forwarding_rule.default",
|
||
|
ImportState: true,
|
||
|
ImportStateVerify: true,
|
||
|
},
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
|
||
|
func testAccComputeGlobalForwardingRule_globalForwardingRuleHttpExample(context map[string]interface{}) string {
|
||
|
return Nprintf(`
|
||
|
resource "google_compute_global_forwarding_rule" "default" {
|
||
|
name = "global-rule-%{random_suffix}"
|
||
|
target = "${google_compute_target_http_proxy.default.self_link}"
|
||
|
port_range = "80"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_target_http_proxy" "default" {
|
||
|
name = "target-proxy-%{random_suffix}"
|
||
|
description = "a description"
|
||
|
url_map = "${google_compute_url_map.default.self_link}"
|
||
|
}
|
||
|
|
||
|
resource "google_compute_url_map" "default" {
|
||
|
name = "url-map-target-proxy-%{random_suffix}"
|
||
|
description = "a description"
|
||
|
default_service = "${google_compute_backend_service.default.self_link}"
|
||
|
|
||
|
host_rule {
|
||
|
hosts = ["mysite.com"]
|
||
|
path_matcher = "allpaths"
|
||
|
}
|
||
|
|
||
|
path_matcher {
|
||
|
name = "allpaths"
|
||
|
default_service = "${google_compute_backend_service.default.self_link}"
|
||
|
|
||
|
path_rule {
|
||
|
paths = ["/*"]
|
||
|
service = "${google_compute_backend_service.default.self_link}"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
resource "google_compute_backend_service" "default" {
|
||
|
name = "backend-%{random_suffix}"
|
||
|
port_name = "http"
|
||
|
protocol = "HTTP"
|
||
|
timeout_sec = 10
|
||
|
|
||
|
health_checks = ["${google_compute_http_health_check.default.self_link}"]
|
||
|
}
|
||
|
|
||
|
resource "google_compute_http_health_check" "default" {
|
||
|
name = "check-backend-%{random_suffix}"
|
||
|
request_path = "/"
|
||
|
check_interval_sec = 1
|
||
|
timeout_sec = 1
|
||
|
}
|
||
|
`, context)
|
||
|
}
|
||
|
|
||
|
func testAccCheckComputeGlobalForwardingRuleDestroy(s *terraform.State) error {
|
||
|
for name, rs := range s.RootModule().Resources {
|
||
|
if rs.Type != "google_compute_global_forwarding_rule" {
|
||
|
continue
|
||
|
}
|
||
|
if strings.HasPrefix(name, "data.") {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
config := testAccProvider.Meta().(*Config)
|
||
|
|
||
|
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/forwardingRules/{{name}}")
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
_, err = sendRequest(config, "GET", url, nil)
|
||
|
if err == nil {
|
||
|
return fmt.Errorf("ComputeGlobalForwardingRule still exists at %s", url)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|