terraform-provider-google/google/resource_compute_target_https_proxy_test.go
The Magician 4af5438dc2 Remove outdated tests (superseded by generated ones) (#2836)
<!-- This change is generated by MagicModules. -->
/cc @rileykarson
2019-01-08 14:09:55 -08:00

241 lines
7.1 KiB
Go

package google
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"google.golang.org/api/compute/v1"
)
const (
canonicalSslCertificateTemplate = "https://www.googleapis.com/compute/v1/projects/%s/global/sslCertificates/%s"
)
func TestAccComputeTargetHttpsProxy_update(t *testing.T) {
t.Parallel()
var proxy compute.TargetHttpsProxy
resourceSuffix := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeTargetHttpsProxyDestroy,
Steps: []resource.TestStep{
{
Config: testAccComputeTargetHttpsProxy_basic1(resourceSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpsProxyExists(
"google_compute_target_https_proxy.foobar", &proxy),
testAccComputeTargetHttpsProxyDescription("Resource created for Terraform acceptance testing", &proxy),
testAccComputeTargetHttpsProxyHasSslCertificate("httpsproxy-test-cert1-"+resourceSuffix, &proxy),
),
},
{
Config: testAccComputeTargetHttpsProxy_basic2(resourceSuffix),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeTargetHttpsProxyExists(
"google_compute_target_https_proxy.foobar", &proxy),
testAccComputeTargetHttpsProxyDescription("Resource created for Terraform acceptance testing", &proxy),
testAccComputeTargetHttpsProxyHasSslCertificate("httpsproxy-test-cert1-"+resourceSuffix, &proxy),
testAccComputeTargetHttpsProxyHasSslCertificate("httpsproxy-test-cert2-"+resourceSuffix, &proxy),
),
},
},
})
}
func testAccCheckComputeTargetHttpsProxyExists(n string, proxy *compute.TargetHttpsProxy) 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.TargetHttpsProxies.Get(
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.Primary.ID {
return fmt.Errorf("TargetHttpsProxy not found")
}
*proxy = *found
return nil
}
}
func testAccComputeTargetHttpsProxyDescription(description string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
return func(s *terraform.State) error {
if proxy.Description != description {
return fmt.Errorf("Wrong description: expected '%s' got '%s'", description, proxy.Description)
}
return nil
}
}
func testAccComputeTargetHttpsProxyHasSslCertificate(cert string, proxy *compute.TargetHttpsProxy) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
certUrl := fmt.Sprintf(canonicalSslCertificateTemplate, config.Project, cert)
for _, sslCertificate := range proxy.SslCertificates {
if sslCertificate == certUrl {
return nil
}
}
return fmt.Errorf("Ssl certificate not found: expected'%s'", certUrl)
}
}
func testAccComputeTargetHttpsProxy_basic1(id string) string {
return fmt.Sprintf(`
resource "google_compute_target_https_proxy" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "httpsproxy-test-%s"
url_map = "${google_compute_url_map.foobar.self_link}"
ssl_certificates = ["${google_compute_ssl_certificate.foobar1.self_link}"]
ssl_policy = "${google_compute_ssl_policy.foobar.self_link}"
}
resource "google_compute_backend_service" "foobar" {
name = "httpsproxy-test-backend-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "httpsproxy-test-health-check-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "httpsproxy-test-url-map-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
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 = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
resource "google_compute_ssl_policy" "foobar" {
name = "sslproxy-test-%s"
description = "my-description"
min_tls_version = "TLS_1_2"
profile = "MODERN"
}
resource "google_compute_ssl_certificate" "foobar1" {
name = "httpsproxy-test-cert1-%s"
description = "very descriptive"
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
}
resource "google_compute_ssl_certificate" "foobar2" {
name = "httpsproxy-test-cert2-%s"
description = "very descriptive"
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
}
`, id, id, id, id, id, id, id)
}
func testAccComputeTargetHttpsProxy_basic2(id string) string {
return fmt.Sprintf(`
resource "google_compute_target_https_proxy" "foobar" {
description = "Resource created for Terraform acceptance testing"
name = "httpsproxy-test-%s"
url_map = "${google_compute_url_map.foobar.self_link}"
ssl_certificates = [
"${google_compute_ssl_certificate.foobar1.self_link}",
"${google_compute_ssl_certificate.foobar2.self_link}",
]
quic_override = "ENABLE"
}
resource "google_compute_backend_service" "foobar" {
name = "httpsproxy-test-backend-%s"
health_checks = ["${google_compute_http_health_check.zero.self_link}"]
}
resource "google_compute_http_health_check" "zero" {
name = "httpsproxy-test-health-check-%s"
request_path = "/"
check_interval_sec = 1
timeout_sec = 1
}
resource "google_compute_url_map" "foobar" {
name = "httpsproxy-test-url-map-%s"
default_service = "${google_compute_backend_service.foobar.self_link}"
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 = "/*"
service = "${google_compute_backend_service.foobar.self_link}"
}
}
resource "google_compute_ssl_policy" "foobar" {
name = "sslproxy-test-%s"
description = "my-description"
min_tls_version = "TLS_1_2"
profile = "MODERN"
}
resource "google_compute_ssl_certificate" "foobar1" {
name = "httpsproxy-test-cert1-%s"
description = "very descriptive"
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
}
resource "google_compute_ssl_certificate" "foobar2" {
name = "httpsproxy-test-cert2-%s"
description = "very descriptive"
private_key = "${file("test-fixtures/ssl_cert/test.key")}"
certificate = "${file("test-fixtures/ssl_cert/test.crt")}"
}
`, id, id, id, id, id, id, id)
}