-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.tf
55 lines (48 loc) · 1.75 KB
/
compute.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
data "archive_file" "otp_lambda_layer" {
type = "zip"
source_dir = "${path.module}/code/lambda_layer"
output_path = "${path.module}/code/lambda_layer.zip"
excludes = [
"${path.module}/code/lambda_layer/.venv",
"${path.module}/code/lambda_layer/**dist-info"
]
}
data "archive_file" "otp_lambda_function" {
type = "zip"
source_dir = "${path.module}/code/lambda_function"
output_path = "${path.module}/code/lambda_function.zip"
excludes = ["${path.module}/code/lambda_function/.venv"]
}
resource "aws_lambda_layer_version" "otp_lambda_layer" {
filename = data.archive_file.otp_lambda_layer.output_path
layer_name = "otp_layer"
compatible_runtimes = ["python3.8"]
}
resource "aws_lambda_function" "otp_lambda_function" {
filename = data.archive_file.otp_lambda_function.output_path
function_name = "otp_function"
role = aws_iam_role.otp_lambda_role.arn
handler = "lambda_function.lambda_handler"
runtime = "python3.8"
layers = [aws_lambda_layer_version.otp_lambda_layer.arn]
source_code_hash = filebase64sha256(data.archive_file.otp_lambda_function.output_path)
environment {
variables = {
TOTP_SECRET = var.otp_secret
}
}
}
resource "aws_lambda_alias" "otp_lambda_alias" {
function_name = aws_lambda_function.otp_lambda_function.function_name
function_version = "$LATEST"
name = "prod"
}
resource "aws_lambda_function_url" "otp_url" {
function_name = aws_lambda_function.otp_lambda_function.function_name
authorization_type = "NONE"
}
resource "aws_lambda_function_url" "test_live" {
function_name = aws_lambda_function.otp_lambda_function.function_name
qualifier = "prod"
authorization_type = "NONE"
}