Skip to content

Commit 707c761

Browse files
Migrate google_compute_firewall_policy_rule resource from DCL to MMv1 (#11360) (#20160)
[upstream:c733f358c45a36b7c4917ee48ed316f6bc5287aa] Signed-off-by: Modular Magician <[email protected]>
1 parent ef7d107 commit 707c761

File tree

3 files changed

+217
-100
lines changed

3 files changed

+217
-100
lines changed

.changelog/11360.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: `google_compute_firewall_policy_rule` now uses MMv1 engine instead of DCL.
3+
```

google/services/compute/resource_compute_firewall_policy_rule_test.go

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,81 @@ func TestAccComputeFirewallPolicyRule_securityProfileGroup_update(t *testing.T)
149149
})
150150
}
151151

152+
func TestAccComputeFirewallPolicyRule_basic(t *testing.T) {
153+
t.Parallel()
154+
155+
context := map[string]interface{}{
156+
"random_suffix": acctest.RandString(t, 10),
157+
"org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)),
158+
}
159+
160+
acctest.VcrTest(t, resource.TestCase{
161+
PreCheck: func() { acctest.AccTestPreCheck(t) },
162+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
163+
Steps: []resource.TestStep{
164+
{
165+
Config: testAccComputeFirewallPolicyRule_basic(context),
166+
},
167+
{
168+
ResourceName: "google_compute_firewall_policy_rule.fw_policy_rule",
169+
ImportState: true,
170+
ImportStateVerify: true,
171+
// Referencing using ID causes import to fail
172+
ImportStateVerifyIgnore: []string{"firewall_policy"},
173+
},
174+
},
175+
})
176+
}
177+
178+
func testAccComputeFirewallPolicyRule_basic(context map[string]interface{}) string {
179+
return acctest.Nprintf(`
180+
resource "google_folder" "folder" {
181+
display_name = "tf-test-folder-%{random_suffix}"
182+
parent = "%{org_name}"
183+
deletion_protection = false
184+
}
185+
186+
resource "google_compute_firewall_policy" "fw_policy" {
187+
parent = google_folder.folder.name
188+
short_name = "tf-test-policy-%{random_suffix}"
189+
description = "Resource created for Terraform acceptance testing"
190+
}
191+
192+
resource "google_network_security_address_group" "address_group" {
193+
name = "tf-test-policy-%{random_suffix}"
194+
parent = "%{org_name}"
195+
description = "Sample global networksecurity_address_group"
196+
location = "global"
197+
items = ["208.80.154.224/32"]
198+
type = "IPV4"
199+
capacity = 100
200+
}
201+
202+
resource "google_compute_firewall_policy_rule" "fw_policy_rule" {
203+
firewall_policy = google_compute_firewall_policy.fw_policy.id
204+
description = "Resource created for Terraform acceptance testing"
205+
priority = 9000
206+
enable_logging = true
207+
action = "allow"
208+
direction = "EGRESS"
209+
disabled = false
210+
tls_inspect = false
211+
212+
match {
213+
layer4_configs {
214+
ip_protocol = "tcp"
215+
ports = [80, 8080]
216+
}
217+
dest_ip_ranges = ["11.100.0.1/32"]
218+
dest_fqdns = ["google.com"]
219+
dest_region_codes = ["US"]
220+
dest_threat_intelligences = ["iplist-known-malicious-ips"]
221+
dest_address_groups = [google_network_security_address_group.address_group.id]
222+
}
223+
}
224+
`, context)
225+
}
226+
152227
func testAccComputeFirewallPolicyRule_securityProfileGroup_basic(context map[string]interface{}) string {
153228
return acctest.Nprintf(`
154229
resource "google_folder" "folder" {
@@ -366,13 +441,14 @@ resource "google_network_security_address_group" "address_group" {
366441
}
367442
368443
resource "google_compute_firewall_policy_rule" "fw_policy_rule1" {
369-
firewall_policy = google_compute_firewall_policy.fw_policy.id
370-
description = "Resource created for Terraform acceptance testing"
371-
priority = 9000
372-
enable_logging = true
373-
action = "allow"
374-
direction = "EGRESS"
375-
disabled = false
444+
firewall_policy = google_compute_firewall_policy.fw_policy.id
445+
description = "Resource created for Terraform acceptance testing"
446+
priority = 9000
447+
enable_logging = true
448+
action = "allow"
449+
direction = "EGRESS"
450+
disabled = false
451+
376452
target_service_accounts = [google_service_account.service_account.email]
377453
target_resources = [
378454
google_compute_network.network1.self_link,
@@ -442,13 +518,14 @@ resource "google_network_security_address_group" "address_group" {
442518
}
443519
444520
resource "google_compute_firewall_policy_rule" "fw_policy_rule1" {
445-
firewall_policy = google_compute_firewall_policy.fw_policy.id
446-
description = "Test description"
447-
priority = 9000
448-
enable_logging = false
449-
action = "deny"
450-
direction = "INGRESS"
451-
disabled = true
521+
firewall_policy = google_compute_firewall_policy.fw_policy.id
522+
description = "Test description"
523+
priority = 9000
524+
enable_logging = false
525+
action = "deny"
526+
direction = "INGRESS"
527+
disabled = false
528+
452529
target_resources = [google_compute_network.network1.self_link]
453530
target_service_accounts = [
454531
google_service_account.service_account.email,

0 commit comments

Comments
 (0)