-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.tf
More file actions
45 lines (39 loc) · 1.58 KB
/
Copy pathmain.tf
File metadata and controls
45 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
data "archive_file" "ebs_volumes_zip" {
type = "zip"
source_file = "${path.module}/source/ebs_volumes.py"
output_path = "${path.module}/source/ebs_volumes.zip"
}
resource "aws_lambda_function" "ebs_volumes_cleanup" {
filename = "${path.module}/source/ebs_volumes.zip"
function_name = "${var.function_prefix}ebs_volumes_cleanup"
role = aws_iam_role.iam_role_for_ebs_cleanup.arn
handler = "ebs_volumes.lambda_handler"
source_code_hash = data.archive_file.ebs_volumes_zip.output_base64sha256
runtime = "python3.8"
memory_size = "512"
timeout = "150"
#architectures = ["arm64"]
environment {
variables = {
DAYS = var.days
DRYRUN = var.dryrun
BUCKET_NAME = var.bucket_name
}
}
}
resource "aws_lambda_permission" "allow_cloudwatch_ebs_volumes_cleanup" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.ebs_volumes_cleanup.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.ebs_volumes_cleanup_cloudwatch_rule.arn
}
resource "aws_cloudwatch_event_rule" "ebs_volumes_cleanup_cloudwatch_rule" {
name = "ebs_volumes_cleanup_lambda_trigger"
schedule_expression = var.ebs_volumes_cleanup_cron
}
resource "aws_cloudwatch_event_target" "ebs_volumes_cleanup_lambda" {
rule = aws_cloudwatch_event_rule.ebs_volumes_cleanup_cloudwatch_rule.name
target_id = "ebs_volumes_cleanup_lambda_target"
arn = aws_lambda_function.ebs_volumes_cleanup.arn
}