-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
80 lines (70 loc) · 2.05 KB
/
main.tf
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
provider "aws" {
region = var.aws_region
shared_credentials_files = var.aws_credentials_file
profile = var.aws_profile
}
resource "aws_iam_role" "lambda_role" {
name = "checker_lambda_role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = "sts:AssumeRole",
Effect = "Allow",
Principal = {
Service = "lambda.amazonaws.com"
},
}
]
})
}
resource "aws_iam_role_policy" "lambda_policy" {
name = "lambda_policy"
role = aws_iam_role.lambda_role.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
Effect = "Allow",
Resource = "arn:aws:logs:*:*:*"
}
]
})
}
resource "aws_lambda_function" "passport_check_lambda" {
filename = "package.zip"
function_name = "UAPassportCheck"
role = aws_iam_role.lambda_role.arn
handler = "lambda_function.lambda_handler"
runtime = "python3.11"
source_code_hash = filebase64sha256("package.zip")
timeout = 300
environment {
variables = {
TELEGRAM_TOKEN = var.telegram_token
TELEGRAM_CHAT_ID = var.telegram_chat_id
PASSPORT_SERIES = var.passport_series
PASSPORT_NUMBER = var.passport_number
}
}
}
resource "aws_cloudwatch_event_rule" "lambda_schedule" {
name = "every-15-minutes"
schedule_expression = "rate(15 minutes)"
}
resource "aws_cloudwatch_event_target" "lambda" {
rule = aws_cloudwatch_event_rule.lambda_schedule.name
arn = aws_lambda_function.passport_check_lambda.arn
}
resource "aws_lambda_permission" "allow_cloudwatch" {
statement_id = "AllowExecutionFromCloudWatch"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.passport_check_lambda.function_name
principal = "events.amazonaws.com"
source_arn = aws_cloudwatch_event_rule.lambda_schedule.arn
}