-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.tf
68 lines (58 loc) · 2.15 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
# ------------------------------------------------------------------------------
# Resources
# ------------------------------------------------------------------------------
resource "aws_lambda_function" "main" {
function_name = var.name_prefix
description = "Terraformed Lambda function."
filename = var.filename
s3_bucket = var.s3_bucket
s3_key = var.s3_key
s3_object_version = var.s3_object_version
source_code_hash = var.source_code_hash
handler = var.handler
runtime = var.runtime
memory_size = var.memory_size
timeout = var.timeout
role = aws_iam_role.main.arn
reserved_concurrent_executions = var.reserved_concurrent_executions
publish = var.publish
vpc_config {
subnet_ids = var.subnet_ids
security_group_ids = aws_security_group.vpc[*].id
}
dynamic "environment" {
for_each = length(var.environment) > 0 ? [1] : []
content {
variables = var.environment
}
}
layers = var.layers
tags = merge(var.tags, { "Name" = var.name_prefix })
}
resource "aws_security_group" "vpc" {
count = length(var.subnet_ids) > 0 ? 1 : 0
name = "${var.name_prefix}-sg"
description = "Terraformed security group."
vpc_id = var.vpc_id
tags = merge(var.tags, { "Name" = "${var.name_prefix}-sg" })
}
resource "aws_iam_role" "main" {
name = "${var.name_prefix}-lambda-role"
assume_role_policy = data.aws_iam_policy_document.assume.json
tags = merge(var.tags, { "Name" = "${var.name_prefix}-lambda-role" })
}
data "aws_iam_policy_document" "assume" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["edgelambda.amazonaws.com", "lambda.amazonaws.com"]
}
}
}
resource "aws_iam_role_policy" "main" {
name = "${var.name_prefix}-lambda-privileges"
role = aws_iam_role.main.name
policy = var.policy
}