Skip to content

Commit

Permalink
compute: forced recreation of google_compute_security_policy on `ty…
Browse files Browse the repository at this point in the history
…pe` updates (GoogleCloudPlatform#12233)
  • Loading branch information
wyardley authored and zeleena committed Nov 18, 2024
1 parent e94f474 commit 751b04b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func ResourceComputeSecurityPolicy() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: `The type indicates the intended use of the security policy. CLOUD_ARMOR - Cloud Armor backend security policies can be configured to filter incoming HTTP requests targeting backend services. They filter requests before they hit the origin servers. CLOUD_ARMOR_EDGE - Cloud Armor edge security policies can be configured to filter incoming HTTP requests targeting backend services (including Cloud CDN-enabled) as well as backend buckets (Cloud Storage). They filter requests before the request is served from Google's cache.`,
ValidateFunc: validation.StringInSlice([]string{"CLOUD_ARMOR", "CLOUD_ARMOR_EDGE", "CLOUD_ARMOR_INTERNAL_SERVICE"}, false),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
Expand All @@ -22,7 +23,48 @@ func TestAccComputeSecurityPolicy_basic(t *testing.T) {
CheckDestroy: testAccCheckComputeSecurityPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSecurityPolicy_basic(spName),
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR"),
},
{
ResourceName: "google_compute_security_policy.policy",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccComputeSecurityPolicy_basicUpdate(t *testing.T) {
t.Parallel()

spName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeSecurityPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_compute_security_policy.policy", "type", "CLOUD_ARMOR"),
),
},
{
ResourceName: "google_compute_security_policy.policy",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR_EDGE"),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_compute_security_policy.policy", plancheck.ResourceActionDestroyBeforeCreate),
},
},
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_compute_security_policy.policy", "type", "CLOUD_ARMOR_EDGE"),
),
},
{
ResourceName: "google_compute_security_policy.policy",
Expand Down Expand Up @@ -212,7 +254,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
CheckDestroy: testAccCheckComputeSecurityPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSecurityPolicy_basic(spName),
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR"),
},
{
ResourceName: "google_compute_security_policy.policy",
Expand Down Expand Up @@ -254,7 +296,7 @@ func TestAccComputeSecurityPolicy_withAdvancedOptionsConfig(t *testing.T) {
ImportStateVerify: true,
},
{
Config: testAccComputeSecurityPolicy_basic(spName),
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR"),
},
{
ResourceName: "google_compute_security_policy.policy",
Expand Down Expand Up @@ -534,7 +576,7 @@ func TestAccComputeSecurityPolicy_withRecaptchaOptionsConfig(t *testing.T) {
CheckDestroy: testAccCheckComputeSecurityPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSecurityPolicy_basic(spName),
Config: testAccComputeSecurityPolicy_basic(spName, "CLOUD_ARMOR"),
},
{
ResourceName: "google_compute_security_policy.policy",
Expand Down Expand Up @@ -782,14 +824,14 @@ func testAccCheckComputeSecurityPolicyDestroyProducer(t *testing.T) func(s *terr
}
}

func testAccComputeSecurityPolicy_basic(spName string) string {
func testAccComputeSecurityPolicy_basic(spName, policyType string) string {
return fmt.Sprintf(`
resource "google_compute_security_policy" "policy" {
name = "%s"
description = "basic security policy"
type = "CLOUD_ARMOR"
type = "%s"
}
`, spName)
`, spName, policyType)
}

func testAccComputeSecurityPolicy_withRule(spName string) string {
Expand Down

0 comments on commit 751b04b

Please sign in to comment.