Skip to content

Commit

Permalink
All log retention syncronized across log groups (#1030)
Browse files Browse the repository at this point in the history
* All log retention syncronized across log groups

* formatting
  • Loading branch information
ben851 authored Nov 16, 2023
1 parent babda95 commit 59478f5
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ override.tf.json
.terragrunt*

# VSCode editor's files
.vscode
.vscode

# aider AI
.aider*
.DS_Store
27 changes: 15 additions & 12 deletions aws/common/cloudwatch_log.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
# AWS CloudWatch Log Groups
###
resource "aws_cloudwatch_log_group" "sns_deliveries" {
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/${var.region}/${var.account_id}/DirectPublishToPhoneNumber"
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/${var.region}/${var.account_id}/DirectPublishToPhoneNumber"
retention_in_days = var.env == "production" ? 0 : 365

tags = {
CostCenter = "notification-canada-ca-${var.env}"
}
}

resource "aws_cloudwatch_log_group" "sns_deliveries_failures" {
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/${var.region}/${var.account_id}/DirectPublishToPhoneNumber/Failure"
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/${var.region}/${var.account_id}/DirectPublishToPhoneNumber/Failure"
retention_in_days = var.env == "production" ? 0 : 365

tags = {
CostCenter = "notification-canada-ca-${var.env}"
Expand All @@ -22,8 +24,9 @@ resource "aws_cloudwatch_log_group" "sns_deliveries_failures" {
resource "aws_cloudwatch_log_group" "sns_deliveries_us_west_2" {
provider = aws.us-west-2

count = var.cloudwatch_enabled ? 1 : 0
name = "sns/us-west-2/${var.account_id}/DirectPublishToPhoneNumber"
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/us-west-2/${var.account_id}/DirectPublishToPhoneNumber"
retention_in_days = var.env == "production" ? 0 : 365

tags = {
CostCenter = "notification-canada-ca-${var.env}"
Expand All @@ -33,19 +36,19 @@ resource "aws_cloudwatch_log_group" "sns_deliveries_us_west_2" {
resource "aws_cloudwatch_log_group" "sns_deliveries_failures_us_west_2" {
provider = aws.us-west-2

count = var.cloudwatch_enabled ? 1 : 0
name = "sns/us-west-2/${var.account_id}/DirectPublishToPhoneNumber/Failure"
count = var.cloudwatch_enabled ? 1 : 0
name = "sns/us-west-2/${var.account_id}/DirectPublishToPhoneNumber/Failure"
retention_in_days = var.env == "production" ? 0 : 365

tags = {
CostCenter = "notification-canada-ca-${var.env}"
}
}

resource "aws_cloudwatch_log_group" "route53_resolver_query_log" {
count = var.cloudwatch_enabled ? 1 : 0
name = "route53/${var.region}/${var.account_id}/DNS/logs"

retention_in_days = 14
count = var.cloudwatch_enabled ? 1 : 0
name = "route53/${var.region}/${var.account_id}/DNS/logs"
retention_in_days = var.env == "production" ? 0 : 365

tags = {
CostCenter = "notification-canada-ca-${var.env}"
Expand Down
6 changes: 3 additions & 3 deletions aws/eks/cloudwatch_log.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
resource "aws_cloudwatch_log_group" "notification-canada-ca-eks-cluster-logs" {
count = var.cloudwatch_enabled ? 1 : 0
name = "/aws/eks/${var.eks_cluster_name}/cluster"
retention_in_days = 14
retention_in_days = var.env == "production" ? 0 : 365
}

resource "aws_cloudwatch_log_group" "notification-canada-ca-eks-application-logs" {
count = var.cloudwatch_enabled ? 1 : 0
name = "/aws/containerinsights/${var.eks_cluster_name}/application"
retention_in_days = var.env == "production" ? 0 : 30
retention_in_days = var.env == "production" ? 0 : 365
}

resource "aws_cloudwatch_log_group" "notification-canada-ca-eks-prometheus-logs" {
count = var.cloudwatch_enabled ? 1 : 0
name = "/aws/containerinsights/${var.eks_cluster_name}/prometheus"
retention_in_days = 0
retention_in_days = var.env == "production" ? 0 : 365
}


Expand Down
4 changes: 2 additions & 2 deletions aws/elasticache/cloudwatch_log.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
resource "aws_cloudwatch_log_group" "notification-canada-ca-elasticache-slow-logs" {
name = "/aws/elasticache/notify-${var.env}-cluster-cache-az/slow-logs"
retention_in_days = 90
retention_in_days = var.env == "production" ? 0 : 365
}

resource "aws_cloudwatch_log_group" "notification-canada-ca-elasticache-engine-logs" {
name = "/aws/elasticache/notify-${var.env}-cluster-cache-az/engine-logs"
retention_in_days = 90
retention_in_days = var.env == "production" ? 0 : 365
}
2 changes: 1 addition & 1 deletion aws/heartbeat/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
resource "aws_cloudwatch_log_group" "heartbeat_log_group" {
count = var.cloudwatch_enabled ? 1 : 0
name = "heartbeat_log_group"
retention_in_days = 90
retention_in_days = var.env == "production" ? 0 : 365
tags = {
CostCenter = "notification-canada-ca-${var.env}"
Environment = var.env
Expand Down
4 changes: 2 additions & 2 deletions aws/lambda-api/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

resource "aws_cloudwatch_log_group" "api_gateway_log_group" {
name = "api_gateway_log_group"
retention_in_days = 0
retention_in_days = var.env == "production" ? 0 : 365
tags = {
CostCenter = "notification-canada-ca-${var.env}"
Environment = var.env
Expand All @@ -15,7 +15,7 @@ resource "aws_cloudwatch_log_group" "api_gateway_log_group" {
resource "aws_cloudwatch_log_group" "api_lambda_log_group" {
count = var.cloudwatch_enabled ? 1 : 0
name = "/aws/lambda/${aws_lambda_function.api.function_name}"
retention_in_days = 0
retention_in_days = var.env == "production" ? 0 : 365
tags = {
CostCenter = "notification-canada-ca-${var.env}"
Environment = var.env
Expand Down
2 changes: 1 addition & 1 deletion aws/performance-test/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_cloudwatch_log_group" "perf_test_ecs_logs" {
count = var.cloudwatch_enabled ? 1 : 0
name = aws_ecs_cluster.perf_test.name
retention_in_days = 14
retention_in_days = var.env == "production" ? 0 : 365
}
2 changes: 1 addition & 1 deletion aws/ses_to_sqs_email_callbacks/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
resource "aws_cloudwatch_log_group" "ses_to_sqs_email_callbacks_log_group" {
count = var.cloudwatch_enabled ? 1 : 0
name = "ses_to_sqs_email_callbacks_log_group"
retention_in_days = 90
retention_in_days = var.env == "production" ? 0 : 365
tags = {
CostCenter = "notification-canada-ca-${var.env}"
Environment = var.env
Expand Down
2 changes: 1 addition & 1 deletion aws/sns_to_sqs_sms_callbacks/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
resource "aws_cloudwatch_log_group" "sns_to_sqs_sms_callbacks_log_group" {
count = var.cloudwatch_enabled ? 1 : 0
name = "sns_to_sqs_sms_callbacks_log_group"
retention_in_days = 90
retention_in_days = var.env == "production" ? 0 : 365
tags = {
CostCenter = "notification-canada-ca-${var.env}"
Environment = var.env
Expand Down

0 comments on commit 59478f5

Please sign in to comment.