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

Add variable to tag VPC flow logs #64

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.1
ENHANCEMENTS:
* Add variables to tag VPC flow log resources

## 2.6.0
ENHANCEMENTS:
* VPC flow logs support
Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,16 @@ variable "vpc_flow_log_kms_key_arn" {
description = "KMS Key ARN to encrypt either the bucket or CW log group to store VPC flow logs. KMS policy must allow access to principal delivery.logs.amazonaws.com or logs.<region>.amazonaws.com, depending the case"
type = string
default = ""
}

variable "vpc_flow_logs_tags" {
description = "Tags to add to the VPC flow logs"
type = map(string)
default = {}
}

variable "vpc_flow_logs_storage_tags" {
description = "Tags to add to S3 bucket and/or CW log group deployed for the VPC flow logs"
type = map(string)
default = {}
}
15 changes: 5 additions & 10 deletions vpc_flow_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ resource "aws_s3_bucket" "bucket" {
count = var.vpc_flow_log_bucket_name != "" ? 1 : 0

bucket = var.vpc_flow_log_bucket_name
tags = {
"Name" = var.vpc_flow_log_bucket_name,
"role" = "storage"
"creation" = "terraform"
}
tags = merge({ Name = var.vpc_flow_log_bucket_name }, var.vpc_flow_logs_storage_tags)
}

data "aws_iam_policy_document" "s3_bucket_policy_doc" {
Expand Down Expand Up @@ -114,6 +110,8 @@ resource "aws_flow_log" "flow_log_s3" {
traffic_type = var.vpc_flow_log_traffic_type
vpc_id = aws_vpc.main.id
log_format = var.vpc_flow_log_custom_format != "" ? var.vpc_flow_log_custom_format : null
tags = var.vpc_flow_logs_tags

destination_options {
file_format = "parquet"
per_hour_partition = true
Expand All @@ -128,11 +126,7 @@ resource "aws_cloudwatch_log_group" "cw_log" {
name = var.vpc_flow_log_cw_log_group_name
retention_in_days = var.vpc_flow_log_retention_period
kms_key_id = var.vpc_flow_log_kms_key_arn != "" ? var.vpc_flow_log_kms_key_arn : null
tags = {
"Name" = var.vpc_flow_log_cw_log_group_name,
"role" = "storage"
"creation" = "terraform"
}
tags = merge({ Name = var.vpc_flow_log_cw_log_group_name }, var.vpc_flow_logs_storage_tags)
}

data "aws_iam_policy_document" "assume_role" {
Expand Down Expand Up @@ -210,4 +204,5 @@ resource "aws_flow_log" "flow_log_cw" {
traffic_type = var.vpc_flow_log_traffic_type
vpc_id = aws_vpc.main.id
log_format = var.vpc_flow_log_custom_format != "" ? var.vpc_flow_log_custom_format : null
tags = var.vpc_flow_logs_tags
}