generated from DNXLabs/terraform-aws-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
lambda.tf
79 lines (70 loc) · 2.2 KB
/
lambda.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
resource "aws_lambda_function" "sftp-idp" {
filename = "${path.module}/sftp-idp.zip"
function_name = "${var.name}-sftp-idp"
role = aws_iam_role.iam_for_lambda_idp.arn
handler = "index.lambda_handler"
source_code_hash = data.archive_file.sftp-idp.output_base64sha256
runtime = "python3.7"
environment {
variables = {
var.creds_store == "dynamo" ? "dynamo_table_name" : "SecretsManagerRegion" = var.creds_store == "dynamo" ? aws_dynamodb_table.authentication.name : data.aws_region.current.name
}
}
}
data "archive_file" "sftp-idp" {
type = "zip"
source_dir = "${path.module}/lambda/source/"
output_path = "${path.module}/sftp-idp.zip"
}
resource "aws_iam_role" "iam_for_lambda_idp" {
name = "${var.name}-iam_for_lambda_idp"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "lambda_logs_idp" {
role = aws_iam_role.iam_for_lambda_idp.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
resource "aws_iam_policy" "sftp-idp" {
name = "${var.name}-sftp-idp"
path = "/"
description = "IAM policy IdP service for SFTP in Lambda"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:SFTP/*"
},
{
"Effect": "Allow",
"Action": "dynamodb:GetItem",
"Resource": "${aws_dynamodb_table.authentication.arn}"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "sftp-idp1" {
role = aws_iam_role.iam_for_lambda_idp.name
policy_arn = aws_iam_policy.sftp-idp.arn
}
resource "aws_iam_role_policy_attachment" "sftp-idp2" {
role = aws_iam_role.iam_for_lambda_idp.name
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}