From 89c6d85ab4b63754bc34d3764848a3acc1289cd8 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 27 Sep 2022 14:05:17 -0700 Subject: [PATCH] change enable on adaptive_protection_config (#6572) (#4726) * change enable on adaptive_protection_config * Update resource_compute_security_policy_test.go.erb lined a bracket Co-authored-by: Edward Sun Signed-off-by: Modular Magician Signed-off-by: Modular Magician Co-authored-by: Edward Sun --- .changelog/6572.txt | 3 +++ .../resource_compute_security_policy.go | 5 ++-- .../resource_compute_security_policy_test.go | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .changelog/6572.txt diff --git a/.changelog/6572.txt b/.changelog/6572.txt new file mode 100644 index 0000000000..5cdcc5cb0e --- /dev/null +++ b/.changelog/6572.txt @@ -0,0 +1,3 @@ +```release-note:bug +compute: fixed unable to manage Cloud Armor `adaptive_protection_config` on `google_compute_security_policy` +``` diff --git a/google-beta/resource_compute_security_policy.go b/google-beta/resource_compute_security_policy.go index 7bb30e81e1..728512819b 100644 --- a/google-beta/resource_compute_security_policy.go +++ b/google-beta/resource_compute_security_policy.go @@ -857,8 +857,9 @@ func expandLayer7DdosDefenseConfig(configured []interface{}) *compute.SecurityPo data := configured[0].(map[string]interface{}) return &compute.SecurityPolicyAdaptiveProtectionConfigLayer7DdosDefenseConfig{ - Enable: data["enable"].(bool), - RuleVisibility: data["rule_visibility"].(string), + Enable: data["enable"].(bool), + RuleVisibility: data["rule_visibility"].(string), + ForceSendFields: []string{"Enable"}, } } diff --git a/google-beta/resource_compute_security_policy_test.go b/google-beta/resource_compute_security_policy_test.go index ab2c467214..99f444afa3 100644 --- a/google-beta/resource_compute_security_policy_test.go +++ b/google-beta/resource_compute_security_policy_test.go @@ -176,6 +176,14 @@ func TestAccComputeSecurityPolicy_withAdaptiveProtection(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccComputeSecurityPolicy_withAdaptiveProtectionUpdate(spName), + }, + { + ResourceName: "google_compute_security_policy.policy", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -453,6 +461,22 @@ resource "google_compute_security_policy" "policy" { `, spName) } +func testAccComputeSecurityPolicy_withAdaptiveProtectionUpdate(spName string) string { + return fmt.Sprintf(` +resource "google_compute_security_policy" "policy" { + name = "%s" + description = "updated description" + + adaptive_protection_config { + layer_7_ddos_defense_config { + enable = false + rule_visibility = "STANDARD" + } + } +} +`, spName) +} + func testAccComputeSecurityPolicy_withRateLimitOptions(spName string) string { return fmt.Sprintf(` resource "google_compute_security_policy" "policy" {