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 (#12233) (#20316)

[upstream:acda2f0f71f92d1b4ff964acffc4de6f88cd585a]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Nov 12, 2024
1 parent 5a7d34c commit 4948856
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/12233.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed permadiff on attempted `type` field updates in `google_computer_security_policy`, updating this field will now force recreation of the resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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
56 changes: 49 additions & 7 deletions google/services/compute/resource_compute_security_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 @@ -24,7 +25,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 @@ -214,7 +256,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 @@ -256,7 +298,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 @@ -384,7 +426,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 @@ -632,14 +674,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 4948856

Please sign in to comment.