From 53cba1087d566cdf02f2b8c0f31d1e91b573b19d Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Wed, 3 Jul 2019 10:43:59 -0700 Subject: [PATCH] Test for unsetting security policy --- ...source_compute_backend_service_test.go.erb | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/third_party/terraform/tests/resource_compute_backend_service_test.go.erb b/third_party/terraform/tests/resource_compute_backend_service_test.go.erb index afbf22267951..c2e9e556ba6f 100644 --- a/third_party/terraform/tests/resource_compute_backend_service_test.go.erb +++ b/third_party/terraform/tests/resource_compute_backend_service_test.go.erb @@ -316,14 +316,27 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckComputeBackendServiceDestroy, Steps: []resource.TestStep{ - resource.TestStep{ - Config: testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName), + { + Config: testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName, "${google_compute_security_policy.policy.self_link}"), Check: resource.ComposeTestCheckFunc( testAccCheckComputeBackendServiceExists( "google_compute_backend_service.foobar", &svc), resource.TestMatchResourceAttr("google_compute_backend_service.foobar", "security_policy", regexp.MustCompile(polName)), ), }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName, ""), + }, + { + ResourceName: "google_compute_backend_service.foobar", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -1017,12 +1030,12 @@ resource "google_compute_http_health_check" "zero" { `, serviceName, checkName) } -func testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName string) string { +func testAccComputeBackendService_withSecurityPolicy(serviceName, checkName, polName, polLink string) string { return fmt.Sprintf(` resource "google_compute_backend_service" "foobar" { name = "%s" health_checks = ["${google_compute_http_health_check.zero.self_link}"] - security_policy = "${google_compute_security_policy.policy.self_link}" + security_policy = "%s" } resource "google_compute_http_health_check" "zero" { @@ -1036,7 +1049,7 @@ resource "google_compute_security_policy" "policy" { name = "%s" description = "basic security policy" } -`, serviceName, checkName, polName) +`, serviceName, polLink, checkName, polName) } func testAccComputeBackendService_withMaxConnections(