@@ -390,6 +390,75 @@ func TestAccComputeRegionBackendService_subsettingUpdate(t *testing.T) {
390
390
}
391
391
{{- end }}
392
392
393
+ func TestAccComputeRegionBackendService_withLogConfig(t *testing.T) {
394
+ t.Parallel()
395
+
396
+ serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
397
+ checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
398
+
399
+ acctest.VcrTest(t, resource.TestCase{
400
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
401
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
402
+ CheckDestroy: testAccCheckComputeRegionBackendServiceDestroyProducer(t),
403
+ Steps: []resource.TestStep{
404
+ {
405
+ // Test: Initial setup with minimal config
406
+ Config: testAccComputeRegionBackendService_withLogConfig(serviceName, checkName, 1.0, "INCLUDE_ALL_OPTIONAL"),
407
+ },
408
+ {
409
+ ResourceName: "google_compute_region_backend_service.foobar",
410
+ ImportState: true,
411
+ ImportStateVerify: true,
412
+ },
413
+ {
414
+ // Test: Update to EXCLUDE_ALL_OPTIONAL mode
415
+ Config: testAccComputeRegionBackendService_withLogConfig(serviceName, checkName, 0.5, "EXCLUDE_ALL_OPTIONAL"),
416
+ },
417
+ {
418
+ ResourceName: "google_compute_region_backend_service.foobar",
419
+ ImportState: true,
420
+ ImportStateVerify: true,
421
+ },
422
+ {
423
+ // Test: Update to CUSTOM mode with fields
424
+ Config: testAccComputeRegionBackendService_withLogConfigOptionalFields(serviceName, checkName),
425
+ },
426
+ {
427
+ ResourceName: "google_compute_region_backend_service.foobar",
428
+ ImportState: true,
429
+ ImportStateVerify: true,
430
+ },
431
+ {
432
+ // Test: CUSTOM mode with empty fields
433
+ Config: testAccComputeRegionBackendService_withLogConfigCustomEmpty(serviceName, checkName),
434
+ },
435
+ {
436
+ ResourceName: "google_compute_region_backend_service.foobar",
437
+ ImportState: true,
438
+ ImportStateVerify: true,
439
+ },
440
+ {
441
+ // Test: Minimum sample rate
442
+ Config: testAccComputeRegionBackendService_withLogConfig(serviceName, checkName, 0.0, "INCLUDE_ALL_OPTIONAL"),
443
+ },
444
+ {
445
+ ResourceName: "google_compute_region_backend_service.foobar",
446
+ ImportState: true,
447
+ ImportStateVerify: true,
448
+ },
449
+ {
450
+ // Test: Disable logging
451
+ Config: testAccComputeRegionBackendService_withLogConfigDisabled(serviceName, checkName),
452
+ },
453
+ {
454
+ ResourceName: "google_compute_region_backend_service.foobar",
455
+ ImportState: true,
456
+ ImportStateVerify: true,
457
+ },
458
+ },
459
+ })
460
+ }
461
+
393
462
func testAccComputeRegionBackendService_ilbBasic_withUnspecifiedProtocol(serviceName, checkName string) string {
394
463
return fmt.Sprintf(`
395
464
resource "google_compute_region_backend_service" "foobar" {
@@ -1224,3 +1293,113 @@ resource "google_compute_region_security_policy" "policy" {
1224
1293
`, serviceName, polLink, polName)
1225
1294
}
1226
1295
{{- end }}
1296
+
1297
+ func testAccComputeRegionBackendService_withLogConfig(serviceName, checkName string, sampleRate float64, optionalMode string) string {
1298
+ return fmt.Sprintf(`
1299
+ resource "google_compute_region_backend_service" "foobar" {
1300
+ name = "%s"
1301
+ health_checks = [google_compute_health_check.health_check.self_link]
1302
+ port_name = "http"
1303
+ protocol = "HTTP"
1304
+ load_balancing_scheme = "INTERNAL_MANAGED"
1305
+ locality_lb_policy = "ROUND_ROBIN"
1306
+
1307
+ log_config {
1308
+ enable = true
1309
+ sample_rate = %v
1310
+ optional_mode = "%s"
1311
+ }
1312
+ }
1313
+
1314
+ resource "google_compute_health_check" "health_check" {
1315
+ name = "%s"
1316
+ http_health_check {
1317
+ port = 80
1318
+ }
1319
+ }
1320
+ `, serviceName, sampleRate, optionalMode, checkName)
1321
+ }
1322
+
1323
+ func testAccComputeRegionBackendService_withLogConfigOptionalFields(serviceName, checkName string) string {
1324
+ return fmt.Sprintf(`
1325
+ resource "google_compute_region_backend_service" "foobar" {
1326
+ name = "%s"
1327
+ health_checks = [google_compute_health_check.health_check.self_link]
1328
+ port_name = "http"
1329
+ protocol = "HTTP"
1330
+ load_balancing_scheme = "INTERNAL_MANAGED"
1331
+ locality_lb_policy = "ROUND_ROBIN"
1332
+
1333
+ log_config {
1334
+ enable = true
1335
+ sample_rate = 0.5
1336
+ optional_mode = "CUSTOM"
1337
+ optional_fields = [
1338
+ "PROTOCOL",
1339
+ "RESPONSE_CODE",
1340
+ "REQUEST_METHOD",
1341
+ "URL_MAP",
1342
+ "BACKEND_TARGET"
1343
+ ]
1344
+ }
1345
+ }
1346
+
1347
+ resource "google_compute_health_check" "health_check" {
1348
+ name = "%s"
1349
+ http_health_check {
1350
+ port = 80
1351
+ }
1352
+ }
1353
+ `, serviceName, checkName)
1354
+ }
1355
+
1356
+ func testAccComputeRegionBackendService_withLogConfigCustomEmpty(serviceName, checkName string) string {
1357
+ return fmt.Sprintf(`
1358
+ resource "google_compute_region_backend_service" "foobar" {
1359
+ name = "%s"
1360
+ health_checks = [google_compute_health_check.health_check.self_link]
1361
+ port_name = "http"
1362
+ protocol = "HTTP"
1363
+ load_balancing_scheme = "INTERNAL_MANAGED"
1364
+ locality_lb_policy = "ROUND_ROBIN"
1365
+
1366
+ log_config {
1367
+ enable = true
1368
+ sample_rate = 0.5
1369
+ optional_mode = "CUSTOM"
1370
+ optional_fields = []
1371
+ }
1372
+ }
1373
+
1374
+ resource "google_compute_health_check" "health_check" {
1375
+ name = "%s"
1376
+ http_health_check {
1377
+ port = 80
1378
+ }
1379
+ }
1380
+ `, serviceName, checkName)
1381
+ }
1382
+
1383
+ func testAccComputeRegionBackendService_withLogConfigDisabled(serviceName, checkName string) string {
1384
+ return fmt.Sprintf(`
1385
+ resource "google_compute_region_backend_service" "foobar" {
1386
+ name = "%s"
1387
+ health_checks = [google_compute_health_check.health_check.self_link]
1388
+ port_name = "http"
1389
+ protocol = "HTTP"
1390
+ load_balancing_scheme = "INTERNAL_MANAGED"
1391
+ locality_lb_policy = "ROUND_ROBIN"
1392
+
1393
+ log_config {
1394
+ enable = false
1395
+ }
1396
+ }
1397
+
1398
+ resource "google_compute_health_check" "health_check" {
1399
+ name = "%s"
1400
+ http_health_check {
1401
+ port = 80
1402
+ }
1403
+ }
1404
+ `, serviceName, checkName)
1405
+ }
0 commit comments