-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlambda_ecr_repos.tf
More file actions
233 lines (203 loc) · 6.82 KB
/
lambda_ecr_repos.tf
File metadata and controls
233 lines (203 loc) · 6.82 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
locals {
lambda_source_arn_prefix = "arn:aws:lambda:${var.aws_region}:${var.imms_account_id}:function:imms-"
lambda_ecr_repositories = {
operation = {
name = "imms-backend-repo"
lambda_source_names = [
"*_get_status",
"*_not_found",
"*_search_imms",
"*_get_imms",
"*_delete_imms",
"*_create_imms",
"*_update_imms"
]
}
batch_processor_filter = {
name = "imms-batch-processor-filter-repo"
lambda_source_names = ["*-batch-processor-filter-lambda"]
}
delta = {
name = "imms-delta-backend-repo"
lambda_source_names = ["*-delta-lambda"]
}
filenameprocessor = {
name = "imms-filenameprocessor-repo"
lambda_source_names = ["*-filenameproc-lambda"]
}
id_sync = {
name = "imms-id-sync-repo"
lambda_source_names = ["*-id-sync-lambda"]
}
mesh_processor = {
name = "imms-mesh-processor-repo"
lambda_source_names = ["*-mesh-processor-lambda"]
}
mns_publisher = {
name = "imms-mns-publisher-repo"
lambda_source_names = ["*-mns-publisher-lambda"]
}
ack_backend = {
name = "imms-ackbackend-repo"
lambda_source_names = ["*-ack-lambda"]
}
recordforwarder = {
name = "imms-recordforwarder-repo"
lambda_source_names = ["*-forwarding-lambda"]
}
recordprocessor = {
name = "imms-recordprocessor-repo"
lifecycle_policy = jsonencode({
rules = [
{
rulePriority = 1
description = "Keep last 10 images."
selection = {
tagStatus = "any"
countType = "imageCountMoreThan"
countNumber = 10
}
action = {
type = "expire"
}
}
]
})
}
redis_sync = {
name = "imms-redis-sync-repo"
lambda_source_names = ["*-redis-sync-lambda"]
}
}
}
#lambda repo
resource "aws_ecr_repository" "lambda_repository" {
for_each = local.lambda_ecr_repositories
image_scanning_configuration {
scan_on_push = true
}
image_tag_mutability = "IMMUTABLE"
name = each.value.name
}
resource "aws_ecr_repository_policy" "lambda_repository_image_retrieval_policy" {
for_each = {
for key, repo in local.lambda_ecr_repositories : key => repo if try(repo.lambda_source_names, null) != null
}
repository = aws_ecr_repository.lambda_repository[each.key].name
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "LambdaECRImageRetrievalPolicy"
Effect = "Allow"
Principal = {
Service = "lambda.amazonaws.com"
}
Action = [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer"
]
Condition = {
StringLike = {
"aws:sourceArn" = formatlist("${local.lambda_source_arn_prefix}%s", each.value.lambda_source_names)
}
}
}
]
})
}
resource "aws_ecr_lifecycle_policy" "lambda_repository_lifecycle_policy" {
for_each = {
for key, repo in local.lambda_ecr_repositories : key => repo if try(repo.lifecycle_policy, null) != null
}
repository = aws_ecr_repository.lambda_repository[each.key].name
policy = each.value.lifecycle_policy
}
moved {
from = aws_ecr_repository.ackbackend_repository
to = aws_ecr_repository.lambda_repository["ack_backend"]
}
moved {
from = aws_ecr_repository_policy.ackbackend_repository_lambda_image_retrieval_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["ack_backend"]
}
moved {
from = aws_ecr_repository.recordprocessor_repository
to = aws_ecr_repository.lambda_repository["recordprocessor"]
}
moved {
from = aws_ecr_lifecycle_policy.recordprocessor_repository_lifecycle_policy
to = aws_ecr_lifecycle_policy.lambda_repository_lifecycle_policy["recordprocessor"]
}
moved {
from = aws_ecr_repository.operation_lambda_repository
to = aws_ecr_repository.lambda_repository["operation"]
}
moved {
from = aws_ecr_repository_policy.operation_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["operation"]
}
moved {
from = aws_ecr_repository.batch_processor_filter_lambda_repository
to = aws_ecr_repository.lambda_repository["batch_processor_filter"]
}
moved {
from = aws_ecr_repository_policy.batch_processor_filter_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["batch_processor_filter"]
}
moved {
from = aws_ecr_repository.delta_lambda_repository
to = aws_ecr_repository.lambda_repository["delta"]
}
moved {
from = aws_ecr_repository_policy.delta_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["delta"]
}
moved {
from = aws_ecr_repository.file_name_processor_lambda_repository
to = aws_ecr_repository.lambda_repository["filenameprocessor"]
}
moved {
from = aws_ecr_repository_policy.filenameprocessor_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["filenameprocessor"]
}
moved {
from = aws_ecr_repository.id_sync_lambda_repository
to = aws_ecr_repository.lambda_repository["id_sync"]
}
moved {
from = aws_ecr_repository_policy.id_sync_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["id_sync"]
}
moved {
from = aws_ecr_repository.forwarder_lambda_repository
to = aws_ecr_repository.lambda_repository["recordforwarder"]
}
moved {
from = aws_ecr_repository_policy.forwarder_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["recordforwarder"]
}
moved {
from = aws_ecr_repository.redis_sync_lambda_repository
to = aws_ecr_repository.lambda_repository["redis_sync"]
}
moved {
from = aws_ecr_repository_policy.redis_sync_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["redis_sync"]
}
moved {
from = aws_ecr_repository.mesh_file_converter_lambda_repository
to = aws_ecr_repository.lambda_repository["mesh_processor"]
}
moved {
from = aws_ecr_repository_policy.mesh_processor_lambda_ECRImageRetreival_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["mesh_processor"]
}
moved {
from = module.mns_publisher.aws_ecr_repository.mns_publisher_lambda_repository
to = aws_ecr_repository.lambda_repository["mns_publisher"]
}
moved {
from = module.mns_publisher.aws_ecr_repository_policy.mns_publisher_lambda_ecr_image_retrieval_policy
to = aws_ecr_repository_policy.lambda_repository_image_retrieval_policy["mns_publisher"]
}