Skip to content

Commit 9677871

Browse files
Adding address groups firewall usage in the examples for Firewall and Network Firewall (#7821) (#5584)
* creating the yaml file for address_group, and addinging in the docs overriding * added the address_groups and provided the update tests * fixed the address_groups type field, tests are passing * fix the address group and the examples to use the address_group in examples * adding the tests for firewall_policy_rule and updating the address_group resource * updating the variable naming usage * fix the usage examples in the global * fixing the variables for the tests, updating the address_group tests * fixing the direction, the tests with region are ok, need to fix the global * removing the updates in the resource compute firewall, requires improvement in address_group resource, fixed the tests for global * removing src_address_group from resource firewall test * refactoring address group operation to call the generic network security, updated the address group resource to accept the field parent, necessary to create project and org level, updated the tests that requires org level for firewall usage * fix the name of the file of address_group, removing default value for location and updating transport_tpg version * adding required for location field * fix the go vet error for the google-provider, updating file to .erb and adding tag to unless is ga Signed-off-by: Modular Magician <[email protected]>
1 parent c311e92 commit 9677871

12 files changed

+273
-226
lines changed

.changelog/7821.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
google_compute_firewall_policy_rule
3+
google_compute_network_firewall_policy_rule
4+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package google
2+
3+
import (
4+
"time"
5+
6+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
7+
)
8+
9+
// NetworkSecurityAddressGroupOperationWaitTime is specific for address group resource because the only difference is that it does not need project param.
10+
func NetworkSecurityAddressGroupOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, activity, userAgent string, timeout time.Duration) error {
11+
// project is not necessary for this operation.
12+
return NetworkSecurityOperationWaitTime(config, op, "", activity, userAgent, timeout)
13+
}

google-beta/resource_compute_firewall_policy_rule_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ resource "google_compute_firewall_policy" "default" {
9595
description = "Resource created for Terraform acceptance testing"
9696
}
9797
98+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
99+
name = "tf-test-policy%{random_suffix}"
100+
parent = "%{org_name}"
101+
description = "Sample global networksecurity_address_group"
102+
location = "global"
103+
items = ["208.80.154.224/32"]
104+
type = "IPV4"
105+
capacity = 100
106+
}
107+
98108
resource "google_compute_firewall_policy_rule" "default" {
99109
firewall_policy = google_compute_firewall_policy.default.id
100110
description = "Resource created for Terraform acceptance testing"
@@ -112,6 +122,7 @@ resource "google_compute_firewall_policy_rule" "default" {
112122
dest_fqdns = []
113123
dest_region_codes = []
114124
dest_threat_intelligences = []
125+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
115126
}
116127
}
117128
`, context)
@@ -148,6 +159,16 @@ resource "google_compute_firewall_policy" "default" {
148159
description = "Resource created for Terraform acceptance testing"
149160
}
150161
162+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
163+
name = "tf-test-policy%{random_suffix}"
164+
parent = "%{org_name}"
165+
description = "Sample global networksecurity_address_group"
166+
location = "global"
167+
items = ["208.80.154.224/32"]
168+
type = "IPV4"
169+
capacity = 100
170+
}
171+
151172
resource "google_compute_firewall_policy_rule" "default" {
152173
firewall_policy = google_compute_firewall_policy.default.id
153174
description = "Resource created for Terraform acceptance testing"
@@ -169,6 +190,8 @@ resource "google_compute_firewall_policy_rule" "default" {
169190
dest_fqdns = ["google.com"]
170191
dest_region_codes = ["US"]
171192
dest_threat_intelligences = ["iplist-known-malicious-ips"]
193+
src_address_groups = []
194+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
172195
}
173196
target_resources = [google_compute_network.network1.self_link, google_compute_network.network2.self_link]
174197
target_service_accounts = [google_service_account.service_account.email]
@@ -207,6 +230,16 @@ resource "google_compute_firewall_policy" "default" {
207230
description = "Resource created for Terraform acceptance testing"
208231
}
209232
233+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
234+
name = "tf-test-policy%{random_suffix}"
235+
parent = "%{org_name}"
236+
description = "Sample global networksecurity_address_group"
237+
location = "global"
238+
items = ["208.80.154.224/32"]
239+
type = "IPV4"
240+
capacity = 100
241+
}
242+
210243
resource "google_compute_firewall_policy_rule" "default" {
211244
firewall_policy = google_compute_firewall_policy.default.id
212245
description = "Test description"
@@ -290,6 +323,16 @@ resource "google_compute_firewall_policy" "default" {
290323
description = "Resource created for Terraform acceptance testing"
291324
}
292325
326+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
327+
name = "tf-test-policy%{random_suffix}"
328+
parent = "%{org_name}"
329+
description = "Sample global networksecurity_address_group"
330+
location = "global"
331+
items = ["208.80.154.224/32"]
332+
type = "IPV4"
333+
capacity = 100
334+
}
335+
293336
resource "google_compute_firewall_policy_rule" "rule1" {
294337
firewall_policy = google_compute_firewall_policy.default.id
295338
description = "Resource created for Terraform acceptance testing"
@@ -307,6 +350,7 @@ resource "google_compute_firewall_policy_rule" "rule1" {
307350
dest_fqdns = ["google.com"]
308351
dest_region_codes = ["US"]
309352
dest_threat_intelligences = ["iplist-known-malicious-ips"]
353+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
310354
}
311355
}
312356
@@ -330,6 +374,7 @@ resource "google_compute_firewall_policy_rule" "rule2" {
330374
src_fqdns = ["google.com"]
331375
src_region_codes = ["US"]
332376
src_threat_intelligences = ["iplist-known-malicious-ips"]
377+
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
333378
}
334379
}
335380
`, context)
@@ -348,6 +393,16 @@ resource "google_compute_firewall_policy" "default" {
348393
description = "Description Update"
349394
}
350395
396+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
397+
name = "tf-test-policy%{random_suffix}"
398+
parent = "%{org_name}"
399+
description = "Sample global networksecurity_address_group"
400+
location = "global"
401+
items = ["208.80.154.224/32"]
402+
type = "IPV4"
403+
capacity = 100
404+
}
405+
351406
resource "google_compute_firewall_policy_rule" "rule1" {
352407
firewall_policy = google_compute_firewall_policy.default.id
353408
description = "Resource created for Terraform acceptance testing"
@@ -364,6 +419,7 @@ resource "google_compute_firewall_policy_rule" "rule1" {
364419
dest_fqdns = ["google.com"]
365420
dest_region_codes = ["US"]
366421
dest_threat_intelligences = ["iplist-known-malicious-ips"]
422+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
367423
}
368424
}
369425
@@ -387,6 +443,7 @@ resource "google_compute_firewall_policy_rule" "rule2" {
387443
src_fqdns = ["google.com"]
388444
src_region_codes = ["US"]
389445
src_threat_intelligences = ["iplist-known-malicious-ips"]
446+
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
390447
}
391448
}
392449
@@ -407,6 +464,7 @@ resource "google_compute_firewall_policy_rule" "rule3" {
407464
src_fqdns = ["google.com"]
408465
src_region_codes = ["US"]
409466
src_threat_intelligences = ["iplist-known-malicious-ips"]
467+
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
410468
}
411469
}
412470
`, context)
@@ -425,6 +483,16 @@ resource "google_compute_firewall_policy" "default" {
425483
description = "Resource created for Terraform acceptance testing"
426484
}
427485
486+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
487+
name = "tf-test-policy%{random_suffix}"
488+
parent = "%{org_name}"
489+
description = "Sample global networksecurity_address_group"
490+
location = "global"
491+
items = ["208.80.154.224/32"]
492+
type = "IPV4"
493+
capacity = 100
494+
}
495+
428496
resource "google_compute_firewall_policy_rule" "rule1" {
429497
firewall_policy = google_compute_firewall_policy.default.id
430498
description = "Resource created for Terraform acceptance testing"

google-beta/resource_compute_network_firewall_policy_rule_generated_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ func TestAccComputeNetworkFirewallPolicyRule_GlobalHandWritten(t *testing.T) {
6666

6767
func testAccComputeNetworkFirewallPolicyRule_GlobalHandWritten(context map[string]interface{}) string {
6868
return Nprintf(`
69+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
70+
name = "tf-test-policy%{random_suffix}"
71+
parent = "projects/%{project_name}"
72+
description = "Sample global networksecurity_address_group"
73+
location = "global"
74+
items = ["208.80.154.224/32"]
75+
type = "IPV4"
76+
capacity = 100
77+
}
78+
6979
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
7080
name = "tf-test-policy%{random_suffix}"
7181
description = "Sample global network firewall policy"
@@ -96,6 +106,8 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
96106
layer4_configs {
97107
ip_protocol = "all"
98108
}
109+
110+
src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
99111
}
100112
}
101113
@@ -124,6 +136,16 @@ resource "google_tags_tag_value" "basic_value" {
124136

125137
func testAccComputeNetworkFirewallPolicyRule_GlobalHandWrittenUpdate0(context map[string]interface{}) string {
126138
return Nprintf(`
139+
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
140+
name = "tf-test-policy%{random_suffix}"
141+
parent = "projects/%{project_name}"
142+
description = "Sample global networksecurity_address_group. Update"
143+
location = "global"
144+
items = ["208.80.154.224/32"]
145+
type = "IPV4"
146+
capacity = 100
147+
}
148+
127149
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
128150
name = "tf-test-policy%{random_suffix}"
129151
description = "Sample global network firewall policy"
@@ -150,6 +172,9 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
150172
ip_protocol = "tcp"
151173
ports = ["123"]
152174
}
175+
176+
dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
177+
153178
}
154179
155180
target_secure_tags {

google-beta/resource_compute_region_network_firewall_policy_rule_generated_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ func TestAccComputeRegionNetworkFirewallPolicyRule_RegionalHandWritten(t *testin
6767

6868
func testAccComputeRegionNetworkFirewallPolicyRule_RegionalHandWritten(context map[string]interface{}) string {
6969
return Nprintf(`
70+
resource "google_network_security_address_group" "basic_regional_networksecurity_address_group" {
71+
name = "tf-test-policy%{random_suffix}"
72+
parent = "projects/%{project_name}"
73+
description = "Sample regional networksecurity_address_group"
74+
location = "%{region}"
75+
items = ["208.80.154.224/32"]
76+
type = "IPV4"
77+
capacity = 100
78+
}
79+
7080
resource "google_compute_region_network_firewall_policy" "basic_regional_network_firewall_policy" {
7181
name = "tf-test-policy%{random_suffix}"
7282
description = "Sample regional network firewall policy"
@@ -99,6 +109,8 @@ resource "google_compute_region_network_firewall_policy_rule" "primary" {
99109
src_secure_tags {
100110
name = "tagValues/${google_tags_tag_value.basic_value.name}"
101111
}
112+
113+
src_address_groups = [google_network_security_address_group.basic_regional_networksecurity_address_group.id]
102114
}
103115
}
104116
@@ -128,6 +140,16 @@ resource "google_tags_tag_value" "basic_value" {
128140

129141
func testAccComputeRegionNetworkFirewallPolicyRule_RegionalHandWrittenUpdate0(context map[string]interface{}) string {
130142
return Nprintf(`
143+
resource "google_network_security_address_group" "basic_regional_networksecurity_address_group" {
144+
name = "tf-test-policy%{random_suffix}"
145+
parent = "projects/%{project_name}"
146+
description = "Sample regional networksecurity_address_group. Update"
147+
location = "%{region}"
148+
items = ["208.80.154.224/32"]
149+
type = "IPV4"
150+
capacity = 100
151+
}
152+
131153
resource "google_compute_region_network_firewall_policy" "basic_regional_network_firewall_policy" {
132154
name = "tf-test-policy%{random_suffix}"
133155
description = "Sample regional network firewall policy"
@@ -156,6 +178,8 @@ resource "google_compute_region_network_firewall_policy_rule" "primary" {
156178
ip_protocol = "tcp"
157179
ports = ["123"]
158180
}
181+
182+
dest_address_groups = [google_network_security_address_group.basic_regional_networksecurity_address_group.id]
159183
}
160184
161185
target_secure_tags {

0 commit comments

Comments
 (0)