Skip to content

Commit 9a766e0

Browse files
[#20905] Add network scope and src network fields to fw policy rules (#12762) (#20951)
[upstream:22ebcfbc1bce625abe2a1a382af8c6312fc8032e] Signed-off-by: Modular Magician <[email protected]>
1 parent ebf96f8 commit 9a766e0

10 files changed

+928
-171
lines changed

.changelog/12762.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
```release-note:enhancement
2+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_firewall_policy_rule` resource (beta)
3+
```
4+
```release-note:enhancement
5+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_firewall_policy_with_rules` resource (beta)
6+
```
7+
```release-note:enhancement
8+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_network_firewall_policy_rule` resource (beta)
9+
```
10+
```release-note:enhancement
11+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_network_firewall_policy_with_rules` resource (beta)
12+
```
13+
```release-note:enhancement
14+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_region_network_firewall_policy_rule` resource (beta)
15+
```
16+
```release-note:enhancement
17+
compute: added `dest_network_scope`, `src_network_scope` and `src_networks` fields to `google_compute_region_network_firewall_policy_with_rules` resource (beta)
18+
```

google/services/compute/resource_compute_firewall_policy_rule_generated_test.go

Lines changed: 94 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func TestAccComputeFirewallPolicyRule_firewallPolicyRuleExample(t *testing.T) {
3535
t.Parallel()
3636

3737
context := map[string]interface{}{
38-
"org_id": envvar.GetTestOrgFromEnv(t),
39-
"service_account": envvar.GetTestServiceAccountFromEnv(t),
40-
"random_suffix": acctest.RandString(t, 10),
38+
"org_id": envvar.GetTestOrgFromEnv(t),
39+
"service_acct": envvar.GetTestServiceAccountFromEnv(t),
40+
"random_suffix": acctest.RandString(t, 10),
4141
}
4242

4343
acctest.VcrTest(t, resource.TestCase{
@@ -49,7 +49,7 @@ func TestAccComputeFirewallPolicyRule_firewallPolicyRuleExample(t *testing.T) {
4949
Config: testAccComputeFirewallPolicyRule_firewallPolicyRuleExample(context),
5050
},
5151
{
52-
ResourceName: "google_compute_firewall_policy_rule.policy_rule",
52+
ResourceName: "google_compute_firewall_policy_rule.primary",
5353
ImportState: true,
5454
ImportStateVerify: true,
5555
ImportStateVerifyIgnore: []string{"firewall_policy"},
@@ -61,7 +61,7 @@ func TestAccComputeFirewallPolicyRule_firewallPolicyRuleExample(t *testing.T) {
6161
func testAccComputeFirewallPolicyRule_firewallPolicyRuleExample(context map[string]interface{}) string {
6262
return acctest.Nprintf(`
6363
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
64-
name = "address%{random_suffix}"
64+
name = "tf-test-address-group%{random_suffix}"
6565
parent = "organizations/%{org_id}"
6666
description = "Sample global networksecurity_address_group"
6767
location = "global"
@@ -78,36 +78,111 @@ resource "google_folder" "folder" {
7878
7979
resource "google_compute_firewall_policy" "default" {
8080
parent = google_folder.folder.id
81-
short_name = "policy%{random_suffix}"
81+
short_name = "tf-test-fw-policy%{random_suffix}"
8282
description = "Resource created for Terraform acceptance testing"
8383
}
8484
85-
resource "google_compute_firewall_policy_rule" "policy_rule" {
85+
resource "google_compute_firewall_policy_rule" "primary" {
86+
firewall_policy = google_compute_firewall_policy.default.name
87+
description = "Resource created for Terraform acceptance testing"
88+
priority = 9000
89+
enable_logging = true
90+
action = "allow"
91+
direction = "EGRESS"
92+
disabled = false
93+
target_service_accounts = ["%{service_acct}"]
94+
95+
match {
96+
dest_ip_ranges = ["11.100.0.1/32"]
97+
dest_fqdns = []
98+
dest_region_codes = ["US"]
99+
dest_threat_intelligences = ["iplist-known-malicious-ips"]
100+
src_address_groups = []
101+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
102+
dest_network_scope = "INTERNET"
103+
104+
layer4_configs {
105+
ip_protocol = "tcp"
106+
ports = [8080]
107+
}
108+
109+
layer4_configs {
110+
ip_protocol = "udp"
111+
ports = [22]
112+
}
113+
}
114+
}
115+
`, context)
116+
}
117+
118+
func TestAccComputeFirewallPolicyRule_firewallPolicyRuleNetworkScopeExample(t *testing.T) {
119+
t.Parallel()
120+
121+
context := map[string]interface{}{
122+
"org_id": envvar.GetTestOrgFromEnv(t),
123+
"random_suffix": acctest.RandString(t, 10),
124+
}
125+
126+
acctest.VcrTest(t, resource.TestCase{
127+
PreCheck: func() { acctest.AccTestPreCheck(t) },
128+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
129+
CheckDestroy: testAccCheckComputeFirewallPolicyRuleDestroyProducer(t),
130+
Steps: []resource.TestStep{
131+
{
132+
Config: testAccComputeFirewallPolicyRule_firewallPolicyRuleNetworkScopeExample(context),
133+
},
134+
{
135+
ResourceName: "google_compute_firewall_policy_rule.primary",
136+
ImportState: true,
137+
ImportStateVerify: true,
138+
ImportStateVerifyIgnore: []string{"firewall_policy"},
139+
},
140+
},
141+
})
142+
}
143+
144+
func testAccComputeFirewallPolicyRule_firewallPolicyRuleNetworkScopeExample(context map[string]interface{}) string {
145+
return acctest.Nprintf(`
146+
resource "google_folder" "folder" {
147+
display_name = "folder%{random_suffix}"
148+
parent = "organizations/%{org_id}"
149+
deletion_protection = false
150+
}
151+
152+
resource "google_compute_firewall_policy" "default" {
153+
parent = google_folder.folder.id
154+
short_name = "tf-test-fw-policy%{random_suffix}"
155+
description = "Firewall policy"
156+
}
157+
158+
resource "google_compute_firewall_policy_rule" "primary" {
86159
firewall_policy = google_compute_firewall_policy.default.name
87-
description = "Resource created for Terraform acceptance testing"
160+
description = "Firewall policy rule with network scope"
88161
priority = 9000
89-
enable_logging = true
90162
action = "allow"
91-
direction = "EGRESS"
163+
direction = "INGRESS"
92164
disabled = false
93165
94166
match {
167+
src_ip_ranges = ["11.100.0.1/32"]
168+
src_network_scope = "VPC_NETWORKS"
169+
src_networks = [google_compute_network.network.id]
170+
95171
layer4_configs {
96172
ip_protocol = "tcp"
97-
ports = [8080]
173+
ports = [8080]
98174
}
175+
99176
layer4_configs {
100177
ip_protocol = "udp"
101-
ports = [22]
178+
ports = [22]
102179
}
103-
dest_ip_ranges = ["11.100.0.1/32"]
104-
dest_fqdns = []
105-
dest_region_codes = ["US"]
106-
dest_threat_intelligences = ["iplist-known-malicious-ips"]
107-
src_address_groups = []
108-
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
109180
}
110-
target_service_accounts = ["%{service_account}"]
181+
}
182+
183+
resource "google_compute_network" "network" {
184+
name = "network%{random_suffix}"
185+
auto_create_subnetworks = false
111186
}
112187
`, context)
113188
}

google/services/compute/resource_compute_network_firewall_policy_rule_generated_test.go

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleExample(t
6262
func testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleExample(context map[string]interface{}) string {
6363
return acctest.Nprintf(`
6464
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
65-
name = "address%{random_suffix}"
65+
name = "tf-test-address-group%{random_suffix}"
6666
parent = "projects/%{project_name}"
6767
description = "Sample global networksecurity_address_group"
6868
location = "global"
@@ -72,7 +72,7 @@ resource "google_network_security_address_group" "basic_global_networksecurity_a
7272
}
7373
7474
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
75-
name = "policy%{random_suffix}"
75+
name = "tf-test-fw-policy%{random_suffix}"
7676
description = "Sample global network firewall policy"
7777
project = "%{project_name}"
7878
}
@@ -89,9 +89,10 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
8989
target_service_accounts = ["%{service_acct}"]
9090
9191
match {
92-
src_ip_ranges = ["10.100.0.1/32"]
93-
src_fqdns = ["google.com"]
94-
src_region_codes = ["US"]
92+
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
93+
src_ip_ranges = ["10.100.0.1/32"]
94+
src_fqdns = ["google.com"]
95+
src_region_codes = ["US"]
9596
src_threat_intelligences = ["iplist-known-malicious-ips"]
9697
9798
src_secure_tags {
@@ -101,8 +102,6 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
101102
layer4_configs {
102103
ip_protocol = "all"
103104
}
104-
105-
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
106105
}
107106
}
108107
@@ -114,7 +113,8 @@ resource "google_tags_tag_key" "basic_key" {
114113
description = "For keyname resources."
115114
parent = "organizations/%{org_id}"
116115
purpose = "GCE_FIREWALL"
117-
short_name = "tagkey%{random_suffix}"
116+
short_name = "tf-test-tag-key%{random_suffix}"
117+
118118
purpose_data = {
119119
network = "%{project_name}/${google_compute_network.basic_network.name}"
120120
}
@@ -123,7 +123,124 @@ resource "google_tags_tag_key" "basic_key" {
123123
resource "google_tags_tag_value" "basic_value" {
124124
description = "For valuename resources."
125125
parent = google_tags_tag_key.basic_key.id
126-
short_name = "tagvalue"
126+
short_name = "tf-test-tag-value%{random_suffix}"
127+
}
128+
`, context)
129+
}
130+
131+
func TestAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeEgressExample(t *testing.T) {
132+
t.Parallel()
133+
134+
context := map[string]interface{}{
135+
"project_name": envvar.GetTestProjectFromEnv(),
136+
"random_suffix": acctest.RandString(t, 10),
137+
}
138+
139+
acctest.VcrTest(t, resource.TestCase{
140+
PreCheck: func() { acctest.AccTestPreCheck(t) },
141+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
142+
CheckDestroy: testAccCheckComputeNetworkFirewallPolicyRuleDestroyProducer(t),
143+
Steps: []resource.TestStep{
144+
{
145+
Config: testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeEgressExample(context),
146+
},
147+
{
148+
ResourceName: "google_compute_network_firewall_policy_rule.primary",
149+
ImportState: true,
150+
ImportStateVerify: true,
151+
ImportStateVerifyIgnore: []string{"firewall_policy"},
152+
},
153+
},
154+
})
155+
}
156+
157+
func testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeEgressExample(context map[string]interface{}) string {
158+
return acctest.Nprintf(`
159+
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
160+
name = "tf-test-fw-policy%{random_suffix}"
161+
description = "Sample global network firewall policy"
162+
project = "%{project_name}"
163+
}
164+
165+
resource "google_compute_network_firewall_policy_rule" "primary" {
166+
action = "allow"
167+
description = "This is a simple rule description"
168+
direction = "EGRESS"
169+
disabled = false
170+
enable_logging = true
171+
firewall_policy = google_compute_network_firewall_policy.basic_network_firewall_policy.name
172+
priority = 1000
173+
rule_name = "test-rule"
174+
175+
match {
176+
dest_ip_ranges = ["10.100.0.1/32"]
177+
dest_network_scope = "INTERNET"
178+
179+
layer4_configs {
180+
ip_protocol = "all"
181+
}
182+
}
183+
}
184+
`, context)
185+
}
186+
187+
func TestAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeIngressExample(t *testing.T) {
188+
t.Parallel()
189+
190+
context := map[string]interface{}{
191+
"project_name": envvar.GetTestProjectFromEnv(),
192+
"random_suffix": acctest.RandString(t, 10),
193+
}
194+
195+
acctest.VcrTest(t, resource.TestCase{
196+
PreCheck: func() { acctest.AccTestPreCheck(t) },
197+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
198+
CheckDestroy: testAccCheckComputeNetworkFirewallPolicyRuleDestroyProducer(t),
199+
Steps: []resource.TestStep{
200+
{
201+
Config: testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeIngressExample(context),
202+
},
203+
{
204+
ResourceName: "google_compute_network_firewall_policy_rule.primary",
205+
ImportState: true,
206+
ImportStateVerify: true,
207+
ImportStateVerifyIgnore: []string{"firewall_policy"},
208+
},
209+
},
210+
})
211+
}
212+
213+
func testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleNetworkScopeIngressExample(context map[string]interface{}) string {
214+
return acctest.Nprintf(`
215+
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
216+
name = "tf-test-fw-policy%{random_suffix}"
217+
description = "Sample global network firewall policy"
218+
project = "%{project_name}"
219+
}
220+
221+
resource "google_compute_network_firewall_policy_rule" "primary" {
222+
action = "allow"
223+
description = "This is a simple rule description"
224+
direction = "INGRESS"
225+
disabled = false
226+
enable_logging = true
227+
firewall_policy = google_compute_network_firewall_policy.basic_network_firewall_policy.name
228+
priority = 1000
229+
rule_name = "test-rule"
230+
231+
match {
232+
src_ip_ranges = ["11.100.0.1/32"]
233+
src_network_scope = "VPC_NETWORKS"
234+
src_networks = [google_compute_network.network.id]
235+
236+
layer4_configs {
237+
ip_protocol = "all"
238+
}
239+
}
240+
}
241+
242+
resource "google_compute_network" "network" {
243+
name = "network%{random_suffix}"
127244
}
128245
`, context)
129246
}

0 commit comments

Comments
 (0)