Skip to content

Commit 28cf94b

Browse files
Fix for (#13677) (#22402)
[upstream:1351767649df52958bbdbe1e60df1a987d82b2c1] Signed-off-by: Modular Magician <[email protected]>
1 parent 4ec5f5e commit 28cf94b

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

.changelog/13677.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
google_compute_network_firewall_policy_rule: Adding diffsuppress for Issue 21775
3+
```

google/services/compute/resource_compute_network_firewall_policy_rule.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ import (
3535
"github.com/hashicorp/terraform-provider-google/google/verify"
3636
)
3737

38+
func SecurityProfileGroupPrefixSlashes(_, old, new string, _ *schema.ResourceData) bool {
39+
if strings.HasPrefix(old, "//") {
40+
old = old[1:]
41+
}
42+
if strings.HasPrefix(new, "//") {
43+
new = new[1:]
44+
}
45+
return old == new
46+
}
47+
3848
func ResourceComputeNetworkFirewallPolicyRule() *schema.Resource {
3949
return &schema.Resource{
4050
Create: resourceComputeNetworkFirewallPolicyRuleCreate,
@@ -243,8 +253,9 @@ Note: you cannot enable logging on "goto_next" rules.`,
243253
Description: `An optional name for the rule. This field is not a unique identifier and can be updated.`,
244254
},
245255
"security_profile_group": {
246-
Type: schema.TypeString,
247-
Optional: true,
256+
Type: schema.TypeString,
257+
Optional: true,
258+
DiffSuppressFunc: SecurityProfileGroupPrefixSlashes,
248259
Description: `A fully-qualified URL of a SecurityProfile resource instance.
249260
Example: https://networksecurity.googleapis.com/v1/projects/{project}/locations/{location}/securityProfileGroups/my-security-profile-group
250261
Must be specified if action = 'apply_security_profile_group' and cannot be specified for other actions.`,

google/services/compute/resource_compute_network_firewall_policy_rule_test.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ func TestAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(t *test
181181
t.Parallel()
182182

183183
context := map[string]interface{}{
184-
"random_suffix": acctest.RandString(t, 10),
185-
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
184+
"random_suffix": acctest.RandString(t, 10),
185+
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
186+
"security_profile_group_prefix": "//",
186187
}
187188

188189
acctest.VcrTest(t, resource.TestCase{
@@ -262,6 +263,33 @@ func TestAccComputeNetworkFirewallPolicyRule_secureTags(t *testing.T) {
262263
})
263264
}
264265

266+
func TestAccComputeNetworkFirewallSecurityProfileGroupDiffsuppress(t *testing.T) {
267+
t.Parallel()
268+
269+
context := map[string]interface{}{
270+
"random_suffix": acctest.RandString(t, 10),
271+
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
272+
"security_profile_group_prefix": "/",
273+
}
274+
275+
acctest.VcrTest(t, resource.TestCase{
276+
PreCheck: func() { acctest.AccTestPreCheck(t) },
277+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
278+
Steps: []resource.TestStep{
279+
{
280+
Config: testAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(context),
281+
},
282+
{
283+
ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule1",
284+
ImportState: true,
285+
ImportStateVerify: true,
286+
// Referencing using ID causes import to fail
287+
ImportStateVerifyIgnore: []string{"firewall_policy"},
288+
},
289+
},
290+
})
291+
}
292+
265293
func testAccComputeNetworkFirewallPolicyRule_secureTags(context map[string]interface{}) string {
266294
return acctest.Nprintf(`
267295
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
@@ -493,7 +521,7 @@ resource "google_compute_network_firewall_policy_rule" "fw_policy_rule1" {
493521
priority = 9000
494522
enable_logging = true
495523
action = "apply_security_profile_group"
496-
security_profile_group = "//networksecurity.googleapis.com/${google_network_security_security_profile_group.security_profile_group_updated.id}"
524+
security_profile_group = "%{security_profile_group_prefix}networksecurity.googleapis.com/${google_network_security_security_profile_group.security_profile_group_updated.id}"
497525
direction = "INGRESS"
498526
disabled = false
499527
match {

0 commit comments

Comments
 (0)