Description
VPC Flow Logs record IP traffic at network interfaces. You can collect records for an entire VPC, a subnet or an individual interface.
Potential impact
If the target is wrong, the connections you need to investigate may be absent from the logs.
Remediation
Set one of vpc_id, subnet_id or eni_id on aws_flow_log for the scope you need. Choose the traffic type and destination, grant delivery permissions and confirm that records from the target arrive.
Examples
The first flow log lacks a target. The second already covers the main VPC. The revised examples send accepted and rejected traffic from that VPC to two distinct log groups. Define both groups and the IAM role. Keep existing Terraform addresses when changing only the collection scope.
Before
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
resource "aws_flow_log" "example" {
iam_role_arn = aws_iam_role.example.arn
log_destination = aws_cloudwatch_log_group.example.arn
traffic_type = "ALL"
}
resource "aws_flow_log" "example1" {
iam_role_arn = aws_iam_role.example.arn
log_destination = aws_cloudwatch_log_group.main.arn
traffic_type = "ALL"
vpc_id = aws_vpc.main.id
}
After
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
}
resource "aws_flow_log" "example" {
iam_role_arn = aws_iam_role.example.arn
log_destination = aws_cloudwatch_log_group.example.arn
traffic_type = "ALL"
vpc_id = aws_vpc.main.id
}
resource "aws_flow_log" "example2" {
iam_role_arn = aws_iam_role.example.arn
log_destination = aws_cloudwatch_log_group.main.arn
traffic_type = "ALL"
vpc_id = aws_vpc.main.id
}