From 5edd77009f94208fac8534e76a0e475842ed1594 Mon Sep 17 00:00:00 2001 From: tajewole-moj Date: Wed, 18 Oct 2023 15:02:57 +0100 Subject: [PATCH] event rules --- terraform/environments/apex/lambda.tf | 21 +++++++++++++++++++ .../apex/module/lambda/outputs.tf | 7 +++++++ terraform/environments/apex/variables.tf | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 terraform/environments/apex/module/lambda/outputs.tf diff --git a/terraform/environments/apex/lambda.tf b/terraform/environments/apex/lambda.tf index eb28aae25a0..50923287bf9 100644 --- a/terraform/environments/apex/lambda.tf +++ b/terraform/environments/apex/lambda.tf @@ -1,5 +1,6 @@ module "iambackup" { source = "./module/lambdapolicy" + backup_policy_name = "laa-${local.application_name}-${local.environment}-policy" tags = merge( local.tags, { Name = "laa-${local.application_name}-${local.environment}-mp" } @@ -25,3 +26,23 @@ runtime = local.runtime { Name = "laa-${local.application_name}-${local.environment}-mp" } ) } + + +resource "aws_cloudwatch_event_rule" "mon_sun" { + name = "${local.application_name}-createSnapshotRule-LWN8E1LNHFJR" + description = "Fires every five minutes" + schedule_expression = "0 2 ? * MON-SUN *" +} + +resource "aws_cloudwatch_event_target" "check_mon_sun" { + rule = aws_cloudwatch_event_rule.mon_sun.name + arn = module.lambda_backup.lambda_function +} + +resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_mon_sun" { + statement_id = "AllowExecutionFromCloudWatch" + action = "lambda:InvokeFunction" + function_name = module.lambda_backup.lambda_function_name + principal = "events.amazonaws.com" + source_arn = aws_cloudwatch_event_rule.mon_sun.arn +} \ No newline at end of file diff --git a/terraform/environments/apex/module/lambda/outputs.tf b/terraform/environments/apex/module/lambda/outputs.tf new file mode 100644 index 00000000000..aa785489f3c --- /dev/null +++ b/terraform/environments/apex/module/lambda/outputs.tf @@ -0,0 +1,7 @@ +output "lambda_function" { + value = aws_lambda_function.snapshotDBFunction.*.arn +} + +output "lambda_function_name" { + value = aws_lambda_function.snapshotDBFunction.*.function_name +} \ No newline at end of file diff --git a/terraform/environments/apex/variables.tf b/terraform/environments/apex/variables.tf index 1e8c9eab892..59385209fc1 100644 --- a/terraform/environments/apex/variables.tf +++ b/terraform/environments/apex/variables.tf @@ -14,16 +14,16 @@ variable "filename" { } variable "function_name" { - type = list(string) + type = list(any) default = ["snapshotDBFunction","deletesnapshotFunction","connectDBFunction"] } variable "handler" { - type = list(string) + type = list(any) default = ["snapshot/dbsnapshot.handler","deletesnapshots.lambda_handler","ssh/dbconnect.handler"] } variable "runtime" { - type = list(string) + type = list(any) default = [ "nodejs18.x","python3.8","nodejs18.x"] } \ No newline at end of file