-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.tf
More file actions
107 lines (95 loc) · 2.23 KB
/
lambda.tf
File metadata and controls
107 lines (95 loc) · 2.23 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
data "aws_caller_identity" "current" {
}
resource "aws_iam_role" "proxy_lambda_execution_role" {
description = "proxy_lambda_execution_role"
tags = var.tags
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow"
}
]
}
EOF
}
resource "aws_iam_role_policy" "proxy_lambda_execution_policy" {
role = aws_iam_role.proxy_lambda_execution_role.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeNetworkInterfaces",
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeVpcs"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:${var.region}:*:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:${var.region}:${var.account_id}:*"
]
}
]
}
EOF
}
resource "aws_security_group" "sg_lambda" {
description = "proxy-lambda-${var.deployment_identifier}"
vpc_id = var.vpc_id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.lambda_ingress_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.lambda_egress_cidr_blocks
}
}
resource "aws_lambda_function" "lambda" {
filename = var.lambda_zip_path
function_name = var.lambda_function_name
role = aws_iam_role.proxy_lambda_execution_role.arn
handler = var.lambda_handler
source_code_hash = base64sha256(filebase64(var.lambda_zip_path))
runtime = var.lambda_runtime
timeout = var.lambda_timeout
memory_size = var.lambda_memory_size
environment {
variables = var.lambda_environment_variables
}
vpc_config {
security_group_ids = [
aws_security_group.sg_lambda.id
]
subnet_ids = var.lambda_subnet_ids
}
tags = var.tags
}