-
Notifications
You must be signed in to change notification settings - Fork 14
/
lambda.tf
143 lines (122 loc) · 3.75 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/v2.55.0
module "lambda_function" {
source = "terraform-aws-modules/lambda/aws"
version = "~> v1.24.0"
function_name = var.lambda_name
description = var.lambda_desc
handler = var.lambda_handler
runtime = var.lambda_runtime
publish = var.lambda_publish
lambda_at_edge = var.lambda_at_edge
source_path = var.lambda_source
policy = aws_iam_policy.lambda.arn
lambda_role = aws_iam_role.lambda.arn
tags = local.tags
##### Store Packages on S3 w/ Lambda Layer #####
#store_on_s3 = var.lambda_s3_store
#s3_bucket = var.lambda_s3_name
#layers = [
# module.lambda_layer_s3.this_lambda_layer_arn,
#]
#environment_variables = {
# Serverless = "Terraform"
#}
################################################
##### Existing Package Stored Locally #####
#create_package = var.lambda_create_package
#local_existing_package = var.lambda_local_package
###########################################
##### Existing Package Stored in S3 #####
#create_package = var.lambda_create_package
#s3_existing_package = {
# bucket = "my-bucket-with-lambda-builds"
# key = aws_s3_bucket_object.my_function.id
#}
##########################################
##### Lambda in VPC #####
#vpc_subnet_ids = module.vpc.intra_subnets
#vpc_security_group_ids = [module.vpc.default_security_group_id]
#attach_network_policy = var.lambda_attach_ntw_policy
#########################
##### Lambda Permissions Triggers #####
#allowed_triggers = {
# APIGatewayAny = {
# service = "apigateway"
# arn = var.api_gateway_arn
# },
# APIGatewayDevPost = {
# service = "apigateway"
# source_arn = var.api_gateway_source_arn
# },
# OneRule = {
# principal = var.lambda_principal
# source_arn = var.lambda_rule_source_arn
# }
#}
#######################################
}
resource "aws_iam_role" "lambda" {
name = "test-lambda-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
}
]
})
}
resource "aws_iam_policy" "lambda" {
name = "test-lambda-policy"
description = ""
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Action = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
Resource = "arn:aws:logs:*:*:*",
Effect = "Allow"
}
]
})
}
resource "aws_iam_role_policy_attachment" "lambda" {
role = aws_iam_role.lambda.name
policy_arn = aws_iam_policy.lambda.arn
}
#resource "aws_s3_bucket_object" "my_function" {
# bucket = var.lambda_s3_bucket
# key = "${filemd5(var.lambda_s3_source)}.zip"
# source = var.lambda_s3_source
#}
#module "lambda_layer_s3" {
# source = "terraform-aws-modules/lambda/aws"
# version = "1.17.0"
#
# create_layer = var.lambda_s3layer
#
# layer_name = var.lambda_s3layer_name
# description = var.lambda_s3layer_desc
# compatible_runtimes = var.lambda_s3layer_compatible_runtimes # [ "runtime1", "runtime2", ... ]
# source_path = var.lambda_s3layer_source
# store_on_s3 = var.lambda_s3layer_store
# s3_bucket = var.lambda_bucket_layer_name
#}
#module "lambda_layer_local" {
# source = "terraform-aws-modules/lambda/aws"
# version = "1.17.0"
#
# create_layer = var.lambda_layer
# layer_name = var.lambda_layer_name
# description = var.lambda_layer_desc
# compatible_runtimes = var.lambda_layer_compatible_runtimes # [ "runtime1", "runtime2", ... ]
# source_path = var.lambda_layer_source
#}