-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
188 lines (168 loc) · 6.35 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
177
178
179
180
181
182
183
184
185
186
187
188
locals {
tags = {
project = var.project_name
environment = var.environment
provider = "easy-lamb-terraform"
}
lambda_functions = { for func in var.functions : func.name => func if func.http == false && func.mqtt == false && func.sqs == false && func.cron == null }
http_functions = { for func in var.functions : func.name => func if func.http == true }
mqtt_functions = { for func in var.functions : func.name => func if func.mqtt == true }
sqs_functions = { for func in var.functions : func.name => func if func.sqs == true }
cron_functions = { for func in var.functions : func.name => func if func.cron != null }
}
module "api_gateway" {
count = length(local.http_functions) > 0 ? 1 : 0
source = "./modules/api_gateway"
project_name = var.project_name
environment = var.environment
api_gateway = {
cors = var.api_gateway.cors
authorizer = [for authorizer in var.api_gateway.authorizer : {
name = authorizer.name
authorizer_uri = authorizer.function_name != null ? module.lambda[authorizer.function_name].function_invoke_arn : null
identity_sources = authorizer.identity_sources
audience = authorizer.audience
issuer = authorizer.issuer
}]
log_retention = var.api_gateway.log_retention
}
}
module "lambda" {
for_each = local.lambda_functions
source = "./modules/lambda"
project_name = var.project_name
environment = var.environment
output_zip_dir = var.output_zip_dir
function = {
name = each.value.name
description = each.value.description
memory = each.value.memory
timeout = each.value.timeout
source = each.value.source
handler = each.value.handler
runtime = each.value.runtime
tracing = each.value.tracing
log_retention = each.value.log_retention
environment = merge(each.value.environment, {
for listener in each.value.sqs_listeners : upper(replace("SQS_QUEUE_URL_${listener}", "-", "_")) => module.sqs[listener].sqs_queue_url
})
policies = each.value.policies
assume_roles = each.value.assume_roles
override_env = each.value.override_env
layers = each.value.layers
architectures = each.value.architectures
}
}
module "cron" {
for_each = local.cron_functions
source = "./modules/cron-lambda"
project_name = var.project_name
environment = var.environment
output_zip_dir = var.output_zip_dir
function = {
name = each.value.name
description = each.value.description
memory = each.value.memory
timeout = each.value.timeout
source = each.value.source
handler = each.value.handler
runtime = each.value.runtime
tracing = each.value.tracing
log_retention = each.value.log_retention
environment = merge(each.value.environment, {
for listener in each.value.sqs_listeners : upper(replace("SQS_QUEUE_URL_${listener}", "-", "_")) => module.sqs[listener].sqs_queue_url
})
policies = each.value.policies
assume_roles = each.value.assume_roles
cron = each.value.cron
override_env = each.value.override_env
layers = each.value.layers
architectures = each.value.architectures
}
}
module "http" {
for_each = local.http_functions
source = "./modules/http-lambda"
api_gateway = {
id = module.api_gateway[0].id
authorizers = module.api_gateway[0].authorizers
execution_arn = module.api_gateway[0].execution_arn
}
project_name = var.project_name
environment = var.environment
function = {
name = each.value.name
description = each.value.description
memory = each.value.memory
timeout = each.value.timeout
source = each.value.source
handler = each.value.handler
runtime = each.value.runtime
tracing = each.value.tracing
log_retention = each.value.log_retention
environment = merge(each.value.environment, {
for listener in each.value.sqs_listeners : upper(replace("SQS_QUEUE_URL_${listener}", "-", "_")) => module.sqs[listener].sqs_queue_url
})
policies = each.value.policies
assume_roles = each.value.assume_roles
http_path = each.value.http_path
http_method = each.value.http_method
authorizer = each.value.authorizer
override_env = each.value.override_env
layers = each.value.layers
extra_routes = each.value.extra_routes
architectures = each.value.architectures
}
}
module "iot" {
for_each = local.mqtt_functions
source = "./modules/iot-lambda"
project_name = var.project_name
environment = var.environment
output_zip_dir = var.output_zip_dir
function = {
name = each.value.name
description = each.value.description
memory = each.value.memory
timeout = each.value.timeout
source = each.value.source
handler = each.value.handler
runtime = each.value.runtime
tracing = each.value.tracing
log_retention = each.value.log_retention
environment = merge(each.value.environment, {
for listener in each.value.sqs_listeners : upper(replace("SQS_QUEUE_URL_${listener}", "-", "_")) => module.sqs[listener].sqs_queue_url
})
policies = each.value.policies
assume_roles = each.value.assume_roles
mqtt = each.value.mqtt
mqtt_sql = each.value.mqtt_sql
override_env = each.value.override_env
layers = each.value.layers
architectures = each.value.architectures
}
}
module "sqs" {
for_each = local.sqs_functions
source = "./modules/sqs-lambda"
project_name = var.project_name
environment = var.environment
output_zip_dir = var.output_zip_dir
function = {
name = each.value.name
description = each.value.description
memory = each.value.memory
timeout = each.value.timeout
source = each.value.source
handler = each.value.handler
runtime = each.value.runtime
tracing = each.value.tracing
log_retention = each.value.log_retention
environment = each.value.environment
policies = each.value.policies
assume_roles = each.value.assume_roles
override_env = each.value.override_env
layers = each.value.layers
architectures = each.value.architectures
}
}