Skip to content

Commit

Permalink
Set empty security policy (#3969)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored and chrisst committed Jul 3, 2019
1 parent 38efb69 commit 729bc16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions google/resource_compute_backend_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ func resourceComputeBackendServiceCreate(d *schema.ResourceData, meta interface{
log.Printf("[DEBUG] Finished creating BackendService %q: %#v", d.Id(), res)

// 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 Expand Up @@ -775,8 +775,8 @@ func resourceComputeBackendServiceUpdate(d *schema.ResourceData, meta interface{
}

// 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
21 changes: 17 additions & 4 deletions google/resource_compute_backend_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,26 @@ func TestAccComputeBackendService_withSecurityPolicy(t *testing.T) {
CheckDestroy: testAccCheckComputeBackendServiceDestroy,
Steps: []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 @@ -941,12 +954,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 @@ -960,7 +973,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

0 comments on commit 729bc16

Please sign in to comment.