@@ -231,3 +231,115 @@ resource "google_compute_subnetwork" "psc_ilb_nat" {
231
231
}
232
232
` , context )
233
233
}
234
+
235
+ func TestAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway (t * testing.T ) {
236
+ t .Parallel ()
237
+
238
+ context := map [string ]interface {}{
239
+ "random_suffix" : acctest .RandString (t , 10 ),
240
+ }
241
+
242
+ acctest .VcrTest (t , resource.TestCase {
243
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
244
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
245
+ CheckDestroy : testAccCheckComputeServiceAttachmentDestroyProducer (t ),
246
+ Steps : []resource.TestStep {
247
+ {
248
+ Config : testAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway (context ),
249
+ },
250
+ {
251
+ ResourceName : "google_compute_service_attachment.default" ,
252
+ ImportState : true ,
253
+ ImportStateVerify : true ,
254
+ ImportStateVerifyIgnore : []string {"target_service" , "region" },
255
+ },
256
+ },
257
+ })
258
+ }
259
+
260
+ func testAccComputeServiceAttachment_serviceAttachmentBasicExampleGateway (context map [string ]interface {}) string {
261
+ return acctest .Nprintf (`
262
+ resource "google_compute_service_attachment" "default" {
263
+ name = "tf-test-sa-%{random_suffix}"
264
+ region = "us-east1"
265
+ description = "A service attachment configured with Terraform"
266
+
267
+ enable_proxy_protocol = false
268
+ connection_preference = "ACCEPT_AUTOMATIC"
269
+ nat_subnets = [google_compute_subnetwork.psc.id]
270
+ target_service = google_network_services_gateway.foobar.self_link
271
+ }
272
+
273
+ resource "google_certificate_manager_certificate" "default" {
274
+ name = "tf-test-sa-certificate-%{random_suffix}"
275
+ location = "us-east1"
276
+ self_managed {
277
+ pem_certificate = file("test-fixtures/cert.pem")
278
+ pem_private_key = file("test-fixtures/private-key.pem")
279
+ }
280
+ }
281
+
282
+ resource "google_compute_network" "default" {
283
+ name = "tf-test-sa-network-%{random_suffix}"
284
+ auto_create_subnetworks = false
285
+ }
286
+
287
+ resource "google_compute_subnetwork" "psc" {
288
+ name = "tf-test-sa-psc-subnet-%{random_suffix}"
289
+ region = "us-east1"
290
+
291
+ network = google_compute_network.default.id
292
+ purpose = "PRIVATE_SERVICE_CONNECT"
293
+ ip_cidr_range = "10.1.0.0/16"
294
+ }
295
+
296
+ resource "google_compute_subnetwork" "proxyonly" {
297
+ name = "tf-test-sa-proxyonly-subnet-%{random_suffix}"
298
+ purpose = "REGIONAL_MANAGED_PROXY"
299
+ ip_cidr_range = "192.168.0.0/23"
300
+ region = "us-east1"
301
+ network = google_compute_network.default.id
302
+ role = "ACTIVE"
303
+ }
304
+
305
+ resource "google_compute_subnetwork" "default" {
306
+ name = "tf-test-sa-default-subnet-%{random_suffix}"
307
+ purpose = "PRIVATE"
308
+ ip_cidr_range = "10.128.0.0/20"
309
+ region = "us-east1"
310
+ network = google_compute_network.default.id
311
+ role = "ACTIVE"
312
+ }
313
+
314
+ resource "google_network_security_gateway_security_policy" "default" {
315
+ name = "tf-test-sa-swp-policy-%{random_suffix}"
316
+ location = "us-east1"
317
+ }
318
+
319
+ resource "google_network_security_gateway_security_policy_rule" "default" {
320
+ name = "tf-test-sa-swp-rule-%{random_suffix}"
321
+ location = "us-east1"
322
+ gateway_security_policy = google_network_security_gateway_security_policy.default.name
323
+ enabled = true
324
+ priority = 1
325
+ session_matcher = "host() == 'example.com'"
326
+ basic_profile = "ALLOW"
327
+ }
328
+
329
+ resource "google_network_services_gateway" "foobar" {
330
+ name = "tf-test-sa-swp-%{random_suffix}"
331
+ location = "us-east1"
332
+ addresses = ["10.128.0.99"]
333
+ type = "SECURE_WEB_GATEWAY"
334
+ ports = [443]
335
+ description = "my description"
336
+ scope = "%s"
337
+ certificate_urls = [google_certificate_manager_certificate.default.id]
338
+ gateway_security_policy = google_network_security_gateway_security_policy.default.id
339
+ network = google_compute_network.default.id
340
+ subnetwork = google_compute_subnetwork.default.id
341
+ delete_swg_autogen_router_on_destroy = true
342
+ depends_on = [google_compute_subnetwork.proxyonly]
343
+ }
344
+ ` , context )
345
+ }
0 commit comments