Skip to content

Commit 5f7e227

Browse files
feat: add filter_expr control in subnet log_config (#360)
* Test commit * feat: adding logging filter_expr control Added filter_expr control to provide control over VPC log filtering * feat: added subnet_flow_filter_expr control * feat: added subnet_flow_logs_filter_expr control * feat: Changed test to non-default filterExpr value * chore: reverted changes on .gitignore
1 parent bf5dd7f commit 5f7e227

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

examples/simple_project/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module "test-vpc-module" {
4949
subnet_flow_logs_interval = "INTERVAL_10_MIN"
5050
subnet_flow_logs_sampling = 0.7
5151
subnet_flow_logs_metadata = "INCLUDE_ALL_METADATA"
52+
subnet_flow_logs_filter = "false"
5253
}
5354
]
5455
}

modules/subnets/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ module "vpc" {
3333
description = "This subnet has a description"
3434
},
3535
{
36-
subnet_name = "subnet-03"
37-
subnet_ip = "10.10.30.0/24"
38-
subnet_region = "us-west1"
39-
subnet_flow_logs = "true"
40-
subnet_flow_logs_interval = "INTERVAL_10_MIN"
41-
subnet_flow_logs_sampling = 0.7
42-
subnet_flow_logs_metadata = "INCLUDE_ALL_METADATA"
36+
subnet_name = "subnet-03"
37+
subnet_ip = "10.10.30.0/24"
38+
subnet_region = "us-west1"
39+
subnet_flow_logs = "true"
40+
subnet_flow_logs_interval = "INTERVAL_10_MIN"
41+
subnet_flow_logs_sampling = 0.7
42+
subnet_flow_logs_metadata = "INCLUDE_ALL_METADATA"
43+
subnet_flow_logs_filter_expr = "true"
4344
}
4445
]
4546
@@ -88,3 +89,4 @@ The subnets list contains maps, where each object represents a subnet. Each map
8889
| subnet\_flow\_logs\_interval | If subnet\_flow\_logs is true, sets the aggregation interval for collecting flow logs | string | `"INTERVAL_5_SEC"` | no |
8990
| subnet\_flow\_logs\_sampling | If subnet\_flow\_logs is true, set the sampling rate of VPC flow logs within the subnetwork | string | `"0.5"` | no |
9091
| subnet\_flow\_logs\_metadata | If subnet\_flow\_logs is true, configures whether metadata fields should be added to the reported VPC flow logs | string | `"INCLUDE_ALL_METADATA"` | no |
92+
| subnet\_flow\_logs\_filter_expr | Export filter defining which VPC flow logs should be logged, see https://cloud.google.com/vpc/docs/flow-logs#filtering for formatting details | string | `"true"` | no |

modules/subnets/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ resource "google_compute_subnetwork" "subnetwork" {
3636
aggregation_interval = lookup(each.value, "subnet_flow_logs_interval", "INTERVAL_5_SEC")
3737
flow_sampling = lookup(each.value, "subnet_flow_logs_sampling", "0.5")
3838
metadata = lookup(each.value, "subnet_flow_logs_metadata", "INCLUDE_ALL_METADATA")
39+
filter_expr = lookup(each.value, "subnet_flow_logs_filter", "true")
3940
}] : []
4041
content {
4142
aggregation_interval = log_config.value.aggregation_interval
4243
flow_sampling = log_config.value.flow_sampling
4344
metadata = log_config.value.metadata
45+
filter_expr = log_config.value.filter_expr
4446
}
4547
}
4648
network = var.network_name

test/integration/simple_project/simple_project_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestSimpleProject(t *testing.T) {
4848
subnet3 := gcloud.Run(t, "compute networks subnets describe subnet-03", gcOpts)
4949
assert.Equal("10.10.30.0/24", subnet3.Get("ipCidrRange").String(), "should have the right CIDR")
5050
assert.False(subnet3.Get("privateIpGoogleAccess").Bool(), "should not have Private Google Access")
51-
expectedLogConfig = `{"aggregationInterval": "INTERVAL_10_MIN","enable": true,"filterExpr": "true","flowSampling": 0.7,"metadata": "INCLUDE_ALL_METADATA"}`
51+
expectedLogConfig = `{"aggregationInterval": "INTERVAL_10_MIN","enable": true,"filterExpr": "false","flowSampling": 0.7,"metadata": "INCLUDE_ALL_METADATA"}`
5252
assert.JSONEq(expectedLogConfig, subnet3.Get("logConfig").String(), "log config should be correct")
5353
})
5454
net.Test()

0 commit comments

Comments
 (0)