Skip to content

Commit 262548a

Browse files
CCM-14149: Support Container Based Lambdas
1 parent ea2157c commit 262548a

7 files changed

Lines changed: 23 additions & 18 deletions

File tree

infrastructure/modules/lambda/data_archive_file_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
data "archive_file" "lambda" {
2-
count = var.package_type == "Zip" ? 1 : 0
2+
count = local.package_type == "zip" ? 1 : 0
33
type = "zip"
44
source_dir = "${path.root}/${var.function_code_base_path}/${var.function_code_dir}"
55

infrastructure/modules/lambda/data_iam_policy_document_ecr.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ data "aws_iam_policy_document" "ecr" {
1818
"ecr:BatchCheckLayerAvailability",
1919
]
2020

21-
resources = ["arn:aws:ecr:${var.region}:${var.aws_account_id}:repository/*"]
21+
resources = [
22+
for repo_name in var.image_repository_names :
23+
"arn:aws:ecr:${var.region}:${var.aws_account_id}:repository/${repo_name}"
24+
]
2225
}
2326
}

infrastructure/modules/lambda/iam_role_policy_ecr.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_iam_role_policy" "ecr" {
2-
count = var.package_type == "Image" ? 1 : 0
2+
count = local.package_type == "image" ? 1 : 0
33
name = "${local.csi}-ecr"
44
role = aws_iam_role.main.id
55
policy = data.aws_iam_policy_document.ecr.json

infrastructure/modules/lambda/lambda_function.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ resource "aws_lambda_function" "main" {
22
description = var.description
33
function_name = local.csi
44
role = aws_iam_role.main.arn
5-
handler = var.package_type == "Zip" ? "${var.function_module_name}.${var.handler_function_name}" : null
6-
runtime = var.package_type == "Zip" ? var.runtime : null
7-
package_type = var.package_type
5+
handler = local.package_type == "zip" ? "${var.function_module_name}.${var.handler_function_name}" : null
6+
runtime = local.package_type == "zip" ? var.runtime : null
7+
package_type = title(local.package_type)
88
publish = true
99
memory_size = var.memory
1010
timeout = var.timeout
1111

12-
s3_bucket = var.package_type == "Zip" ? aws_s3_object.lambda[0].bucket : null
13-
s3_key = var.package_type == "Zip" ? aws_s3_object.lambda[0].key : null
14-
s3_object_version = var.package_type == "Zip" ? aws_s3_object.lambda[0].version_id : null
12+
s3_bucket = local.package_type == "zip" ? aws_s3_object.lambda[0].bucket : null
13+
s3_key = local.package_type == "zip" ? aws_s3_object.lambda[0].key : null
14+
s3_object_version = local.package_type == "zip" ? aws_s3_object.lambda[0].version_id : null
1515

16-
image_uri = var.package_type == "Image" ? var.image_uri : null
16+
image_uri = local.package_type == "image" ? var.image_uri : null
1717

1818
dynamic "image_config" {
19-
for_each = var.package_type == "Image" && var.image_config != null ? [1] : []
19+
for_each = local.package_type == "image" && var.image_config != null ? [1] : []
2020
content {
2121
entry_point = try(var.image_config.entry_point, null)
2222
command = try(var.image_config.command, null)
@@ -31,7 +31,7 @@ resource "aws_lambda_function" "main" {
3131
system_log_level = var.system_log_level
3232
}
3333

34-
layers = var.package_type == "Zip" ? compact(concat(
34+
layers = local.package_type == "zip" ? compact(concat(
3535
var.layers,
3636
[
3737
var.enable_lambda_insights && var.lambda_at_edge == false ? "arn:aws:lambda:${var.region}:580247275435:layer:LambdaInsightsExtension:53" : null

infrastructure/modules/lambda/locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
locals {
22
module = "lambda"
33

4+
package_type = lower(var.package_type)
5+
46
# Compound Scope Identifier
57
csi = replace(
68
format(

infrastructure/modules/lambda/s3_object_lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_s3_object" "lambda" {
2-
count = var.package_type == "Zip" ? 1 : 0
2+
count = local.package_type == "zip" ? 1 : 0
33
bucket = var.function_s3_bucket
44
key = "${local.csi}.zip"
55
source = data.archive_file.lambda[0].output_path

infrastructure/modules/lambda/variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ variable "runtime" {
9595
default = null
9696

9797
validation {
98-
condition = var.package_type != "Zip" || (var.runtime != null && var.runtime != "")
98+
condition = lower(var.package_type) != "zip" || (var.runtime != null && var.runtime != "")
9999
error_message = "runtime must be set when package_type is Zip."
100100
}
101101
}
@@ -106,7 +106,7 @@ variable "package_type" {
106106
default = "Zip"
107107

108108
validation {
109-
condition = contains(["Zip", "Image"], var.package_type)
109+
condition = contains(["zip", "image"], lower(var.package_type))
110110
error_message = "package_type must be either Zip or Image."
111111
}
112112
}
@@ -117,7 +117,7 @@ variable "image_uri" {
117117
default = null
118118

119119
validation {
120-
condition = var.package_type != "Image" || (var.image_uri != null && var.image_uri != "")
120+
condition = lower(var.package_type) != "image" || (var.image_uri != null && var.image_uri != "")
121121
error_message = "image_uri must be set when package_type is Image."
122122
}
123123
}
@@ -163,7 +163,7 @@ variable "function_code_dir" {
163163
default = null
164164

165165
validation {
166-
condition = var.package_type != "Zip" || (var.function_code_dir != null && var.function_code_dir != "")
166+
condition = lower(var.package_type) != "zip" || (var.function_code_dir != null && var.function_code_dir != "")
167167
error_message = "function_code_dir must be set when package_type is Zip."
168168
}
169169
}
@@ -174,7 +174,7 @@ variable "function_s3_bucket" {
174174
default = null
175175

176176
validation {
177-
condition = var.package_type != "Zip" || (var.function_s3_bucket != null && var.function_s3_bucket != "")
177+
condition = lower(var.package_type) != "zip" || (var.function_s3_bucket != null && var.function_s3_bucket != "")
178178
error_message = "function_s3_bucket must be set when package_type is Zip."
179179
}
180180
}

0 commit comments

Comments
 (0)