Skip to content

Commit

Permalink
chore(billing-report): adding new schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
kiraum committed Sep 29, 2024
1 parent ec3a6bd commit e6cc0ba
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion environments/prod/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module "billing_report" {
source = "../../modules/billing_report"

lambda_function_name = "billing-report-lambda"
sns_topic_name = "root-account-topic"
sns_topic_name = "billing-report-topic"
email_subscription = "[email protected]"
dynamodb_table_name = "CostExplorerProcessedDates"
ruler_name = "billing-report-daily-schedule"
Expand Down
55 changes: 43 additions & 12 deletions modules/billing_report/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,54 @@ resource "aws_scheduler_schedule" "daily_billing_report" {
}
}

resource "aws_kms_key" "lambda_key" {
description = "Default key that protects my Lambda functions when no other key is defined"
enable_key_rotation = true
bypass_policy_lockout_safety_check = false
# Create EventBridge scheduler for weekly billing report (Mondays at 7 AM CEST)
resource "aws_scheduler_schedule" "weekly_billing_report" {
name = "billing-report-weekly-schedule"
group_name = "default"

flexible_time_window {
mode = "OFF"
}

schedule_expression = "cron(0 5 ? * MON *)" # 7 AM CEST on Mondays

lifecycle {
ignore_changes = [tags, tags_all]
target {
arn = aws_lambda_function.billing_report.arn
role_arn = aws_iam_role.scheduler_role.arn
}
}

resource "aws_kms_key" "sns_key" {
description = "Default key that protects my SNS data when no other key is defined"
enable_key_rotation = true
bypass_policy_lockout_safety_check = false
# Create EventBridge scheduler for monthly billing report (1st day of each month at 7 AM CEST)
resource "aws_scheduler_schedule" "monthly_billing_report" {
name = "billing-report-monthly-schedule"
group_name = "default"

flexible_time_window {
mode = "OFF"
}

schedule_expression = "cron(0 5 1 * ? *)" # 7 AM CEST on the 1st day of each month

lifecycle {
ignore_changes = [tags, tags_all]
target {
arn = aws_lambda_function.billing_report.arn
role_arn = aws_iam_role.scheduler_role.arn
}
}

# Create EventBridge scheduler for yearly billing report (January 1st at 7 AM CEST)
resource "aws_scheduler_schedule" "yearly_billing_report" {
name = "billing-report-yearly-schedule"
group_name = "default"

flexible_time_window {
mode = "OFF"
}

schedule_expression = "cron(0 5 1 1 ? *)" # 7 AM CEST on January 1st

target {
arn = aws_lambda_function.billing_report.arn
role_arn = aws_iam_role.scheduler_role.arn
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/billing_report/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variable "lambda_function_name" {
variable "sns_topic_name" {
description = "Name of the SNS topic"
type = string
default = "root-account-topic"
default = "billing-report-topic"
}

variable "email_subscription" {
Expand Down

0 comments on commit e6cc0ba

Please sign in to comment.