@@ -62,7 +62,7 @@ func TestAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleExample(t
62
62
func testAccComputeNetworkFirewallPolicyRule_networkFirewallPolicyRuleExample (context map [string ]interface {}) string {
63
63
return acctest .Nprintf (`
64
64
resource "google_network_security_address_group" "basic_global_networksecurity_address_group" {
65
- name = "address%{random_suffix}"
65
+ name = "tf-test- address-group %{random_suffix}"
66
66
parent = "projects/%{project_name}"
67
67
description = "Sample global networksecurity_address_group"
68
68
location = "global"
@@ -72,7 +72,7 @@ resource "google_network_security_address_group" "basic_global_networksecurity_a
72
72
}
73
73
74
74
resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" {
75
- name = "policy%{random_suffix}"
75
+ name = "tf-test-fw- policy%{random_suffix}"
76
76
description = "Sample global network firewall policy"
77
77
project = "%{project_name}"
78
78
}
@@ -89,9 +89,10 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
89
89
target_service_accounts = ["%{service_acct}"]
90
90
91
91
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"]
95
96
src_threat_intelligences = ["iplist-known-malicious-ips"]
96
97
97
98
src_secure_tags {
@@ -101,8 +102,6 @@ resource "google_compute_network_firewall_policy_rule" "primary" {
101
102
layer4_configs {
102
103
ip_protocol = "all"
103
104
}
104
-
105
- src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id]
106
105
}
107
106
}
108
107
@@ -114,7 +113,8 @@ resource "google_tags_tag_key" "basic_key" {
114
113
description = "For keyname resources."
115
114
parent = "organizations/%{org_id}"
116
115
purpose = "GCE_FIREWALL"
117
- short_name = "tagkey%{random_suffix}"
116
+ short_name = "tf-test-tag-key%{random_suffix}"
117
+
118
118
purpose_data = {
119
119
network = "%{project_name}/${google_compute_network.basic_network.name}"
120
120
}
@@ -123,7 +123,124 @@ resource "google_tags_tag_key" "basic_key" {
123
123
resource "google_tags_tag_value" "basic_value" {
124
124
description = "For valuename resources."
125
125
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}"
127
244
}
128
245
` , context )
129
246
}
0 commit comments