Skip to content

Commit aff9e5d

Browse files
committed
added optional mode and optional fields with tests
1 parent 6df63a8 commit aff9e5d

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed

mmv1/products/compute/RegionBackendService.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ properties:
12971297
at_least_one_of:
12981298
- 'log_config.0.enable'
12991299
- 'log_config.0.sample_rate'
1300+
- 'log_config.0.optional_mode'
13001301
- name: 'sampleRate'
13011302
type: Double
13021303
description: |
@@ -1307,8 +1308,28 @@ properties:
13071308
at_least_one_of:
13081309
- 'log_config.0.enable'
13091310
- 'log_config.0.sample_rate'
1311+
- 'log_config.0.optional_mode'
13101312
diff_suppress_func: 'suppressWhenDisabled'
13111313
default_value: 1.0
1314+
- name: 'optionalMode'
1315+
type: Enum
1316+
description: |
1317+
Specifies the optional logging mode for the load balancer traffic.
1318+
Supported values: INCLUDE_ALL_OPTIONAL, EXCLUDE_ALL_OPTIONAL, CUSTOM.
1319+
enum_values:
1320+
- 'INCLUDE_ALL_OPTIONAL'
1321+
- 'EXCLUDE_ALL_OPTIONAL'
1322+
- 'CUSTOM'
1323+
at_least_one_of:
1324+
- 'log_config.0.enable'
1325+
- 'log_config.0.sample_rate'
1326+
- 'log_config.0.optional_mode'
1327+
- name: 'optionalFields'
1328+
type: Array
1329+
description: |
1330+
Specifies the fields to include in logging. This field can only be specified if logging is enabled for this backend service.
1331+
item_type:
1332+
type: String
13121333
- name: 'network'
13131334
type: ResourceRef
13141335
description: |

mmv1/third_party/terraform/services/compute/resource_compute_region_backend_service_test.go.tmpl

+179
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,75 @@ func TestAccComputeRegionBackendService_subsettingUpdate(t *testing.T) {
390390
}
391391
{{- end }}
392392

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+
393462
func testAccComputeRegionBackendService_ilbBasic_withUnspecifiedProtocol(serviceName, checkName string) string {
394463
return fmt.Sprintf(`
395464
resource "google_compute_region_backend_service" "foobar" {
@@ -1224,3 +1293,113 @@ resource "google_compute_region_security_policy" "policy" {
12241293
`, serviceName, polLink, polName)
12251294
}
12261295
{{- 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

Comments
 (0)