Skip to content

Commit a21b090

Browse files
Samir-CitNA2047
authored andcommitted
SWP Policy Rule - Mitigate multiple rules issue (GoogleCloudPlatform#12704)
1 parent 95468d3 commit a21b090

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

mmv1/products/networksecurity/GatewaySecurityPolicyRule.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async:
4343
delete_minutes: 30
4444
result:
4545
resource_inside_response: false
46-
custom_code:
46+
mutex: 'gatewaySecurityPolicies/{{gateway_security_policy}}/rules'
4747
examples:
4848
- name: 'network_security_gateway_security_policy_rules_basic'
4949
primary_resource_id: 'default'

mmv1/third_party/terraform/services/networksecurity/resource_network_security_gateway_security_policy_rule_test.go

+117
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,50 @@ func TestAccNetworkSecurityGatewaySecurityPolicyRule_update(t *testing.T) {
4848
})
4949
}
5050

51+
func TestAccNetworkSecurityGatewaySecurityPolicyRule_multiple(t *testing.T) {
52+
t.Parallel()
53+
54+
context := map[string]interface{}{
55+
"random_suffix": acctest.RandString(t, 10),
56+
}
57+
58+
acctest.VcrTest(t, resource.TestCase{
59+
PreCheck: func() { acctest.AccTestPreCheck(t) },
60+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
61+
CheckDestroy: testAccCheckNetworkSecurityGatewaySecurityPolicyRuleDestroyProducer(t),
62+
Steps: []resource.TestStep{
63+
{
64+
Config: testAccNetworkSecurityGatewaySecurityPolicyRule_multiple(context),
65+
},
66+
{
67+
ResourceName: "google_network_security_gateway_security_policy_rule.rule1",
68+
ImportState: true,
69+
ImportStateVerify: true,
70+
},
71+
{
72+
ResourceName: "google_network_security_gateway_security_policy_rule.rule2",
73+
ImportState: true,
74+
ImportStateVerify: true,
75+
},
76+
{
77+
ResourceName: "google_network_security_gateway_security_policy_rule.rule3",
78+
ImportState: true,
79+
ImportStateVerify: true,
80+
},
81+
{
82+
ResourceName: "google_network_security_gateway_security_policy_rule.rule4",
83+
ImportState: true,
84+
ImportStateVerify: true,
85+
},
86+
{
87+
ResourceName: "google_network_security_gateway_security_policy_rule.rule5",
88+
ImportState: true,
89+
ImportStateVerify: true,
90+
},
91+
},
92+
})
93+
}
94+
5195
func testAccNetworkSecurityGatewaySecurityPolicyRule_basic(gatewaySecurityPolicyName, gatewaySecurityPolicyRuleName string) string {
5296
return fmt.Sprintf(`
5397
resource "google_network_security_gateway_security_policy" "default" {
@@ -92,3 +136,76 @@ resource "google_network_security_gateway_security_policy_rule" "foobar" {
92136
}
93137
`, gatewaySecurityPolicyName, gatewaySecurityPolicyRuleName)
94138
}
139+
140+
func testAccNetworkSecurityGatewaySecurityPolicyRule_multiple(context map[string]interface{}) string {
141+
return acctest.Nprintf(`
142+
resource "google_network_security_gateway_security_policy" "default" {
143+
name = "tf-test-gateway-sp-%{random_suffix}"
144+
location = "us-central1"
145+
description = "gateway security policy created to be used as reference by the rule."
146+
}
147+
148+
resource "google_network_security_gateway_security_policy_rule" "rule1" {
149+
name = "tf-test-gateway-sp-rule1-%{random_suffix}"
150+
location = "us-central1"
151+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
152+
enabled = true
153+
description = "Highest priority rule"
154+
priority = 0
155+
session_matcher = "host() == 'example.com'"
156+
application_matcher = "request.method == 'POST'"
157+
basic_profile = "ALLOW"
158+
}
159+
160+
resource "google_network_security_gateway_security_policy_rule" "rule2" {
161+
name = "tf-test-gateway-sp-rule2-%{random_suffix}"
162+
location = "us-central1"
163+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
164+
enabled = true
165+
description = "Rule priority 762"
166+
priority = 762
167+
session_matcher = "host() == 'example.com'"
168+
application_matcher = "request.method == 'GET'"
169+
tls_inspection_enabled = false
170+
basic_profile = "DENY"
171+
}
172+
173+
resource "google_network_security_gateway_security_policy_rule" "rule3" {
174+
name = "tf-test-gateway-sp-rule3-%{random_suffix}"
175+
location = "us-central1"
176+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
177+
enabled = true
178+
description = "Rule priority 37961"
179+
priority = 37961
180+
session_matcher = "host() == 'update.com'"
181+
application_matcher = "request.method == 'POST'"
182+
basic_profile = "ALLOW"
183+
}
184+
185+
resource "google_network_security_gateway_security_policy_rule" "rule4" {
186+
name = "tf-test-gateway-sp-rule4-%{random_suffix}"
187+
location = "us-central1"
188+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
189+
enabled = true
190+
description = "Rule priority 9572843"
191+
priority = 9572843
192+
session_matcher = "host() == 'update.com'"
193+
application_matcher = "request.method == 'GET'"
194+
tls_inspection_enabled = false
195+
basic_profile = "DENY"
196+
}
197+
198+
resource "google_network_security_gateway_security_policy_rule" "rule5" {
199+
name = "tf-test-gateway-sp-rule5-%{random_suffix}"
200+
location = "us-central1"
201+
gateway_security_policy = google_network_security_gateway_security_policy.default.name
202+
enabled = true
203+
description = "Lowest priority rule"
204+
priority = 2147483647
205+
session_matcher = "host() == 'update.com'"
206+
application_matcher = "request.method == 'GET'"
207+
tls_inspection_enabled = false
208+
basic_profile = "DENY"
209+
}
210+
`, context)
211+
}

0 commit comments

Comments
 (0)