Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support for VPC Flow Logs in Parquet format #700

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ You can add additional tags with `intra_subnet_tags` as with other subnet types.

VPC Flow Log allows to capture IP traffic for a specific network interface (ENI), subnet, or entire VPC. This module supports enabling or disabling VPC Flow Logs for entire VPC. If you need to have VPC Flow Logs for subnet or ENI, you have to manage it outside of this module with [aws_flow_log resource](https://www.terraform.io/docs/providers/aws/r/flow_log.html).

### VPC Flow Log Examples

By default `file_format` is `plain-text`. You can also specify `parquet` to have logs written in Apache Parquet format.

```
log_file_format = "parquet"
```

### Permissions Boundary

If your organization requires a permissions boundary to be attached to the VPC Flow Log role, make sure that you specify an ARN of the permissions boundary policy as `vpc_flow_log_permissions_boundary` argument. Read more about required [IAM policy for publishing flow logs](https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs-cwl.html#flow-logs-iam).
Expand Down
19 changes: 19 additions & 0 deletions examples/vpc-flow-logs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ module "vpc_with_flow_logs_s3_bucket" {
}
}

module "vpc_with_flow_logs_s3_bucket_parquet" {
source = "../../"

name = "vpc-flow-logs-s3-bucket"
cidr = "10.30.0.0/16"

azs = ["${local.region}a"]
public_subnets = ["10.30.101.0/24"]

enable_flow_log = true
flow_log_destination_type = "s3"
flow_log_destination_arn = module.s3_bucket.this_s3_bucket_arn
log_file_format = "parquet"

vpc_flow_log_tags = {
Name = "vpc-flow-logs-s3-bucket"
}
}

# CloudWatch Log Group and IAM role created automatically
module "vpc_with_flow_logs_cloudwatch_logs_default" {
source = "../../"
Expand Down
23 changes: 23 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1151,3 +1151,26 @@ variable "outpost_az" {
type = string
default = null
}

variable "log_file_format" {
description = "(Optional) The format for the flow log. Valid values: `plain-text`, `parquet`."
type = string
default = "plain-text"
validation {
condition = can(regex("^(plain-text|parquet)$",
var.log_file_format))
error_message = "ERROR valid values: plain-text, parquet."
}
}

variable "hive_compatible_partitions" {
description = "(Optional) Indicates whether to use Hive-compatible prefixes for flow logs stored in Amazon S3."
type = bool
default = false
}

variable "per_hour_partition" {
description = "(Optional) Indicates whether to partition the flow log per hour. This reduces the cost and response time for queries."
type = bool
default = false
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.38"
version = ">= 3.63"
}
}
}
5 changes: 5 additions & 0 deletions vpc-flow-logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ resource "aws_flow_log" "this" {
traffic_type = var.flow_log_traffic_type
vpc_id = local.vpc_id
max_aggregation_interval = var.flow_log_max_aggregation_interval
destination_options {
drewmullen marked this conversation as resolved.
Show resolved Hide resolved
file_format = var.log_file_format
drewmullen marked this conversation as resolved.
Show resolved Hide resolved
hive_compatible_partitions = var.hive_compatible_partitions
per_hour_partition = var.per_hour_partition
}

tags = merge(var.tags, var.vpc_flow_log_tags)
}
Expand Down