Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set empty security policy #2009

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// security_policy isn't set by Create / Update
if v, ok := d.GetOk("security_policy"); ok {
pol, err := ParseSecurityPolicyFieldValue(v.(string), d, config)
if o, n := d.GetChange("security_policy"); o.(string) != n.(string) {
pol, err := ParseSecurityPolicyFieldValue(n.(string), d, config)
if err != nil {
return errwrap.Wrapf("Error parsing Backend Service security policy: {{err}}", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
}
Expand Down Expand Up @@ -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" {
Expand All @@ -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(
Expand Down