terraform-provider-google/google/resource_compute_url_map_generated_test.go
2019-01-02 16:44:08 -08:00

153 lines
3.8 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 TestAccComputeUrlMap_urlMapBasicExample(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: testAccCheckComputeUrlMapDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeUrlMap_urlMapBasicExample(context),
},
{
ResourceName: "google_compute_url_map.urlmap",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccComputeUrlMap_urlMapBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_url_map" "urlmap" {
name = "urlmap-%{random_suffix}"
description = "a description"
default_service = "${google_compute_backend_service.home.self_link}"
host_rule {
hosts = ["mysite.com"]
path_matcher = "allpaths"
}
path_matcher {
name = "allpaths"
default_service = "${google_compute_backend_service.home.self_link}"
path_rule {
paths = ["/home"]
service = "${google_compute_backend_service.home.self_link}"
}
path_rule {
paths = ["/login"]
service = "${google_compute_backend_service.login.self_link}"
}
path_rule {
paths = ["/static"]
service = "${google_compute_backend_bucket.static.self_link}"
}
}
test {
service = "${google_compute_backend_service.home.self_link}"
host = "hi.com"
path = "/home"
}
}
resource "google_compute_backend_service" "login" {
name = "login-%{random_suffix}"
port_name = "http"
protocol = "HTTP"
timeout_sec = 10
health_checks = ["${google_compute_http_health_check.default.self_link}"]
}
resource "google_compute_backend_service" "home" {
name = "home-%{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 = "health-check-%{random_suffix}"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_backend_bucket" "static" {
name = "static-asset-backend-bucket-%{random_suffix}"
bucket_name = "${google_storage_bucket.static.name}"
enable_cdn = true
}
resource "google_storage_bucket" "static" {
name = "static-asset-bucket-%{random_suffix}"
location = "US"
}
`, context)
}
func testAccCheckComputeUrlMapDestroy(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_url_map" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := testAccProvider.Meta().(*Config)
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/urlMaps/{{name}}")
if err != nil {
return err
}
_, err = sendRequest(config, "GET", url, nil)
if err == nil {
return fmt.Errorf("ComputeUrlMap still exists at %s", url)
}
}
return nil
}