This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.tf
177 lines (134 loc) · 4.86 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* # Terraform AWS module for AWS Lambda
*
* ## Introduction
* This module creates an AWS lambda and all the related resources. It is a complete re-write of our internal terraform lambda module.
*
* ## Usage
* Checkout [examples](./examples) on how to use this module for various trigger sources.
* ## Authors
*
* Module managed by [Comtravo](https://github.com/comtravo).
*
* ## License
*
* MIT Licensed. See LICENSE for full details.
*/
# Create the lambda function
resource "aws_lambda_function" "lambda" {
filename = var.file_name
function_name = var.function_name
s3_bucket = var.s3_bucket
s3_key = var.s3_key
s3_object_version = var.s3_object_version
layers = var.layers
handler = var.handler
role = var.role
description = var.description
memory_size = var.memory_size
runtime = var.runtime
timeout = var.timeout
reserved_concurrent_executions = var.reserved_concurrent_executions
publish = var.publish
source_code_hash = local.source_code_hash
image_uri = var.image_uri
package_type = var.image_uri != null ? "Image" : "Zip"
dynamic "image_config" {
for_each = var.image_config == null ? [] : [var.image_config]
content {
command = image_config.value.command
entry_point = image_config.value.entry_point
working_directory = image_config.value.working_directory
}
}
tracing_config {
mode = var.tracing_config.mode
}
vpc_config {
subnet_ids = var.vpc_config.subnet_ids
security_group_ids = var.vpc_config.security_group_ids
}
dynamic "environment" {
for_each = var.environment == null ? [] : [var.environment]
content {
variables = environment.value
}
}
tags = local.tags
}
resource "aws_cloudwatch_log_group" "lambda" {
name = local.cloudwatch_log_group_name
retention_in_days = var.cloudwatch_log_retention
}
module "triggered-by-cloudwatch-event-schedule" {
enable = var.trigger.type == "cloudwatch-event-schedule"
source = "./triggers/cloudwatch_event_schedule/"
lambda_function_arn = aws_lambda_function.lambda.arn
schedule_config = {
name = var.function_name
description = var.description
schedule_expression = lookup(var.trigger, "schedule_expression", "")
}
}
module "triggered-by-cloudwatch-event-trigger" {
enable = var.trigger.type == "cloudwatch-event-trigger"
source = "./triggers/cloudwatch_event_trigger/"
lambda_function_arn = aws_lambda_function.lambda.arn
event_config = {
name = var.function_name
description = var.description
event_pattern = lookup(var.trigger, "event_pattern", "")
}
}
module "triggered-by-step-function" {
enable = var.trigger.type == "step-function"
source = "./triggers/step_function/"
lambda_function_arn = aws_lambda_function.lambda.arn
region = var.region
}
module "triggered-by-api-gateway" {
enable = var.trigger.type == "api-gateway"
source = "./triggers/api_gateway/"
lambda_function_arn = aws_lambda_function.lambda.arn
}
module "triggered-by-cognito-idp" {
enable = var.trigger.type == "cognito-idp"
source = "./triggers/cognito_idp/"
lambda_function_arn = aws_lambda_function.lambda.arn
}
module "triggered-by-cloudwatch-logs" {
enable = var.trigger.type == "cloudwatch-logs"
source = "./triggers/cloudwatch_logs/"
lambda_function_arn = aws_lambda_function.lambda.arn
region = var.region
}
module "triggered-by-sqs" {
enable = var.trigger.type == "sqs"
source = "./triggers/sqs/"
lambda_function_arn = aws_lambda_function.lambda.arn
sqs_config = {
sns_topics = try(var.trigger.sns_topics, [])
sqs_name = var.function_name
visibility_timeout_seconds = var.timeout + 5
batch_size = tonumber(try(var.trigger.batch_size, "1"))
fifo = tobool(try(var.trigger.fifo, false))
}
tags = local.tags
}
module "triggered_by_kinesis" {
source = "./triggers/kinesis/"
lambda_function_arn = aws_lambda_function.lambda.arn
kinesis_configuration = var.kinesis_configuration
}
module "sqs_external" {
source = "./triggers/sqs_external/"
lambda_function_arn = aws_lambda_function.lambda.arn
sqs_external = var.sqs_external
}
module "cloudwatch-log-subscription" {
enable = var.cloudwatch_log_subscription.enable
source = "./log_subscription/"
lambda_name = aws_lambda_function.lambda.function_name
log_group_name = aws_cloudwatch_log_group.lambda.name
cloudwatch_log_subscription = var.cloudwatch_log_subscription
}